Quantcast
Channel: Design Bit
Viewing all 38 articles
Browse latest View live

Deploying your MVC3 application for free using AppHarbor.

$
0
0

Today I’d Like to show you guys how you can easily deploy your MVC3 application
using AppHarbor.

Register your free AppHarbor account.

Visit the AppHarbor website and create your very own
account, for free.

Create your AppHarbor application.

Once you have your account set up and confirmed your email address, create your
AppHarbor application.

Create a service hook for your BitBucket repository.

This is assuming you have your code repository hosted on
BitBucket; of course there are integrations for
Github and a whole array of code repository services if that’s your flavor.

Visit the service hooks page for your project and link things up. An HTML
select element will list all of your repositories on BitBucket, just choose
the one you want to publish on AppHarbor. You will need to give AppHarbor the
necessary permissions in order to do so.

Write some code, and hg push it.

Make some changes to your code base – edit some HTML, write some C#, whatever.
All you need to do is hg push your code to BitBucket and AppHarbor will pull
the latest changeset, and automatically publish your application.

Is that slick or what?

All of this: for free – When your applications grows to production needs,
all you need to do is pay 10$/month for a 10GB database add-on.

After finding out about this service I can’t go back to manually publishing
things anymore. Using a DCVS and automatic publishing? Coding bliss.


How to create a music player notification using HTML and CSS.

$
0
0

Today I’d like to show you guys how to create a sleek music player notification using nothing but HTML and CSS. The main benefit of this approach is that it’ll look good on any device, and you don’t need to rely on images for scaling.

(Original design credit: http://dribbble.com/shots/530948-Transparent-Ui)

Here’s the end result – (Live Demo):

enter image description here


Writing the HTML.

Let’s start by writing the HTML we’re going to need to display the notification.

<div class="player">
  <div class="top-overlay"></div>

  <div class="info">
    <p class="title">The Rain is Gone</p>
    <p class="artist">Everythings a Ripple - Dub FX</p>    
  </div>

  <div class="separator"></div>

  <div class="art">
    <img src="http://i.imgur.com/gS18w.png" alt="Album Art" />
  </div>      
</div>

enter image description here

The markup is pretty straight forward and explicit in it’s intent.

Apply some style to the notification.

(Note: I’m using LESS to write some clean CSS.)

Let’s start by styling the actual .player div. This is the container for the entire notification. I’m using the very excellent tool called CSS Gradient Generator to write some cross-browser gradient styles.

.player {
  height: 105px;
  width: 308px;
  margin: 40px auto;
  position:relative;  
  border:1px solid #0B090A;
  border-radius:2px;
  box-shadow: -1px 1px 8px 1px #222;
  background: #252135;
  background: -moz-linear-gradient(top,  #252135 0%, #231e28 100%); /* FF3.6+ */
  background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#252135), color-stop(100%,#231e28)); /* Chrome,Safari4+ */
  background: -webkit-linear-gradient(top,  #252135 0%,#231e28 100%); /* Chrome10+,Safari5.1+ */
  background: -o-linear-gradient(top,  #252135 0%,#231e28 100%); /* Opera 11.10+ */
  background: -ms-linear-gradient(top,  #252135 0%,#231e28 100%); /* IE10+ */
  background: linear-gradient(to bottom,  #252135 0%,#231e28 100%); /* W3C */
  filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#252135', endColorstr='#231e28',GradientType=0 ); /* IE6-9 */
}

enter image description here

Next, let’s add a faint white overlay to the top of the notification. This gives it a nice finish.

.top-overlay {
  background-color: rgba(255, 255, 255, 0.20);
  position: absolute;
  height: 1px;
  width: 100%;
}

enter image description here

Now lets tackle the song information area. We collect all of that in the .info div.

.info {
  float: left;
  width: 203px;

  .title {
    color: #FAFDFF;
    font-size: 14px;
    text-shadow: rgba(35, 32, 35, 1) 0px 2px 0px;
    margin: 10px 0px 0px 12px;
  }

  .artist {
    color: #C8CBCD;
    font-size: 12px;
    text-shadow: rgba(35, 32, 35, 1) 0px 2px 0px;
    margin: 10px 0px 0px 12px;
  }
}

enter image description here

Let’s style the album art area. Simple enough.

.art {
  float: right;

  img {
    width: 80px;
    height: 80px;
    border-radius: 5px;
    margin-right: 10px;
    margin-top: 13px;
  }
}

enter image description here

And finally, style the separator. This is the divider between the song information and the song album art.

.separator {
  background-color: #151515;
  width: 1px;
  height: 100%;
  border-left: 1px solid #383640;
  border-right: 1px solid #383640;
  float: left;
  margin-left: 0px;
}

enter image description here


The end result looks really nice and is very easy to customize.

Upgrade YouTube with downloads, quality options and more using YousableTubeFix.

$
0
0

I use a userscript called YousableTubeFix. It can be downloaded here: http://userscripts.org/scripts/show/57201

(You can also find versions for Firefox and Opera)

Using this simple script you can totally transform the way you use YouTube. It’s as if you started using a non-buggy version of YouTube, the way it should have been all along.

Here’s are some pretty cool features this extension brings to the table.


Video downloads.

Yes, you can easily download any YouTube video with a click of a button. It doesn’t take you to a “downloader” website or anything, it just starts downloading. It’s magic! (But really, it’s Javascript)

enter image description here

Configuration for default video quality.

Are you stuck on a slow connection at work? Or just want to load the video as quickly as possible? Sometimes, I suffer from both and having to switch to 240 quality every time I watch a video is a pain. Not anymore with this handy configuration. Just click the configuration button below any video page, and select your default quality setting. Every video from here on out will carry that video setting.

enter image description here

Video Window size.

Have a big monitor? Just choose a huge window size and every video will use that setting.

enter image description here


This script will change your life! If you love watching videos from /r/videos or you just like following the latest YouTube channels, this will definitely help you have a smooth experience.

How to install VMWare Guest Tools on Ubuntu 12.10 and Linux Mint 14.

$
0
0

I’m going to show you how to install VMWare Guest Tools on both Ubuntu 12.10 and Linux Mint 14. It’s quite simple and having it installed properly gives you a ton of benefits when working on a virtual machine.

(I work on a Linux Mint 14 virtual machine when doing Rails work – so I need this puppy to be really fast. Almost native speeds.)


  • Go to the VM toolbar menu.
  • Select Install VMWare tools...
  • In your virtual machine, open the mounted drive.
  • Extract the files within the .tar.gz file.
  • Open up a terminal and cd your way to the location of the vmware-install.pl file.
  • Run the following command: sudo ./vmware-install.pl
  • When prompted for choices just keep pressing enter if you want the defaults (I know I do).

When you restart your virtual machine everything will be properly installed and configured.

Since Linux Mint is based on Ubuntu, these steps apply for both distros.

How to create a signature form for iPad and mobile devices using HTML5 and Canvas.

$
0
0

Today I was tasked with creating a “Terms of Service” form where users could sign using their fingers to give it a more personal touch.

Demo

enter image description here


I’m using the fantastic library called Signature Pad, created by Thomas J Bradley.

Initial Setup

You need to reference the following scripts and stylesheets:

<link rel=stylesheet href="jquery.signaturepad.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="json2.min.js"></script>
<script src="jquery.signaturepad.min.js"></script>

That’s:

  1. Signature Pad’s own CSS styles (which you are encouraged to modify)
  2. CDN for jQuery.
  3. Json2 script.
  4. The actual Signature Pad plugin.

The HTML markup needed:

You only need to create a form with a class .sigPad and follow a simple structure.

<form method="post" action="#" class="sigPad">
    <p class="drawItDesc">Acepto los terminos y condiciones de uso.</p>
    <ul class="sigNav">
        <li class="drawIt"><a href="#draw-it">Firma:</a></li>
        <li class="clearButton"><a href="#clear">Borrar</a></li>
    </ul>
    <div class="sig sigWrapper">
        <div class="typed"></div>
            <canvas class="pad" width="335" height="80"></canvas>
            <input type="hidden" name="output" class="output">
        </div>
    <button type="submit">Acepto los terminos y condiciones de uso.</button>
</form>

Notice we’re using the HTML5 canvas element!

Using the Plugin

Using the plugin is ridiculously simple:

$(document).ready(function () {
    $('.sigPad').signaturePad({
        drawOnly: true
    });
});

How do I save the signature?

Personally, I would recommend converting the canvas to a base64 data image. You can then POST that data value and convert it to an actual image server side.

getSignatureImage() // Returns a Base64 encoded PNG of the canvas

Recommended reading:

You can find the complete API for the library here: http://thomasjbradley.ca/lab/signature-pad/#api

Installing RuboCop in Atom.

$
0
0

RubyCop is a great way to make sure your team is following a clear set of Ruby programming standards. It makes sure you use current syntax, avoid unnecessary returns, improve if statement syntaxes and more.

Installing it in Atom is extremely easy due to it's packaging system.

Here's how you do it!


(This guide assumes you're using the latest version of Atom (>= 0.210.0))

Updated June 26th, 2015! (This guide assumes you're using the latest version of Atom (>= 1.0))

Install RuboCop

$ gem install rubocop

This will install the RuboCop executable that lints your Ruby and Rails code.

Install Atom Linter

$ apm install linter

This will install the base linter that runs all other linter dialects.

Install linter-rubocop

$ apm install linter-rubocop

This will install the RuboCop linter that checks your code against RuboCop's rules. It's triggered off of every save and you don't have to do anything to use it.

Just type your code and RuboCop will keep your ego in check.


And that's all there is to it. RuboCop in a nutshell, extremely simple to use.

Meteor Environment Variables

$
0
0

If you come from Ruby on Rails you're used to setting your environment variables in your .ENV file or in your config/application.yml file.

Meteor handles environment variables in a similar way.


Create settings.json file

Inside your server folder in your project, create a file and name it settings.json. Add this file to your gitignore file.

Inside this JSON file, you can save any environment variables you need.

{
  "facebookAppId": "6666667527666666",
  "facebookAppSecret": "00004b20dd845637777321cd3c750000",
  "amazonS3Bucket": "bucket-name"
}

Loading the environment variables

To use these values inside your app during runtime, start Meteor with a --settings option flag.

$ meteor run --settings server/settings.json

Use the values

To use the values, just call the Meteor.settings object.

ServiceConfiguration.configurations.upsert(  
  { service: "facebook" },
  {
    $set: {
      appId: Meteor.settings.facebookAppId, 
      secret: Meteor.settings.facebookAppSecret
    }
  }
);

That's all there is to it! Keep your settings safe, and do not commit your keys.

Meteor React tutorial updated - match made in heaven.

$
0
0

Meteor is still kind of in that wild west style point in time where things move fast, and today's good advice is tomorrow's bad practice.

(RIP IronRouter)

In this article, I'm going to teach you how to integrate React into a Meteor application in a clear, concise no bullshit way. It's going to use current best practices, proven packages, and easy to understand folder/file structure.

Why should you use React? Read this article if you want to see what the hype is about. If this article doesn't convince then you maybe React isn't for you.

Let's get started.


First create the project.

meteor create reactexample  
cd reactexample  

Add the package we're going to need.

meteor add react  
meteor add kadira:react-layout  
meteor add kadira:flow-router  

The react package is the official MDG Meteor package for React integration.

The kadira:react-layout package is going to allow us to natively invoke React components in our routes.

And finally kadira:flow-router is going to allow us to route urls to render specific components.


Erase the original three files generated for your brand new project, and create a folder called client.

In there create a main.html and a main.jsx.

<!-- This is inside main.html -->  
<head>  
  <title>Example React App</title>
</head>

<body>  
  <div id="react-root"></div>
</body>

// This is inside main.jsx
MainLayout = React.createClass({  
  render() {
    return (
      <div>
        <Header />
        <div class="container">
          {this.props.content}
        </div>
        <Footer />
      </div>
    )
  }
});

Notice how the .html file has a #react-root div. That's where the MainLayout is going to be rendered, let's wire that up.

Create a folder called lib at your root and a file called router.jsx inside.

FlowRouter.route('/', {  
  action() {
    ReactLayout.render(MainLayout, { content: <Wall /> });
  }
});

Whenever someone visits the root path, we're going to render the MainLayout component to the #react-root div. Notice we're also passing along a parameter, a simple dummy React component. Let's create these components next.

Make your folders looks something like:

/client
  /components
    wall.jsx
  /layout
    footer.jsx
    header.jsx
/lib
  router.jsx

Cool stuff! So we have a folder for our components and another for our layout components such as Header and Footer.

// This is inside header.jsx
Header = React.createClass({  
  render() {
    return (
      <div class="header">
        <p>This is the header.</p>
      </div>
    )
  }
})

// This is inside footer.jsx
Footer = React.createClass({  
  render() {
    return (
      <div class="footer">
        <p>This is the footer.</p>
      </div>
    )
  }
});

// This is inside wall.jsx
Wall = React.createClass({  
  render() {
    return (
      <div class="footer">
        <h1>Welcome to the Wall!</h1>
      </div>
    )
  }
});

Now run your server and you should see your React components rendered nicely.

In the next article, I'm going to be creating some Components that use Mongo data - again super simple stuff, and you'll see that by using React you've made publishing and subscribing even easier to reason about.


Phoenix Framework Database Migrations

$
0
0

Here's a couple of useful snippets for running database migrations.


How to create a database migration:

mix ecto.gen.migration create_user
// creates .../migrations/20151216023702_create_user.exs

Then inside of this file you write what you want created:

defmodule Example.Repo.Migrations.CreateUser do use Ecto.Migration  
  def change do
    create table(:users) do
      add :name, :string
      add :username, :string, null: false add :password_hash, :string

      timestamps
    end

    create unique_index(:users, [:username]) 
  end
end  

Finally you can migrate with:

mix ecto.migrate  

This is very similar to Rails. I'll be adding more useful Phoenix tidbits here and there as I come across them.

How to seed your Meteor database?

$
0
0

I come from a strong Rails background, where seeding info into your database is super simple and intuitive.

My brother and I are building an open source "Golden path" Meteor application called Mercadera. We want people to have this clear example of how to build a great Meteor application with MongoDB and React.

https://github.com/danieltapia/mercadera

With that objective in mind, the database seed strategy had to be one that made sense, was easy to understand and was safe to use.

Here's our approach.


Structuring your seeds file.

See an example here:

The idea is that you write all your seed information in a simple file called seeds.js. You wrap all of your document creation instructions inside a Meteor method.

We're using Astronomy for the data-layer in Meteor. It brings a nice solid foundation to any Meteor application in that you declare your structure in one place and that is your wall of defense for dirty data.

If you were to run this seeds file multiple times, it wouldn't add the same categories or cities twice, we have unique validators in our model.

Meteor.methods({  
  'Database.seed': function() {
    // Create initial Category documents.
    var categories = [
      'Bienes Raices',
      'Automoviles',
      'Electrodomesticos',
      'Computadoras'
    ];
    _.forEach(categories, function(c) {
      var category = new Category();
      category.set({
        name: c,
        createdAt: new Date(),
        totalListings: 0
      });
      category.generateSlug();
      if (category.validate()) {
        category.save();
      }
    });

    // Create initial City documents.
    var cities = [
      'Santa Cruz',
      'La Paz',
      'Cochabamba',
      'Tarija',
      'Oruro',
      'Sucre',
      'Beni',
      'Potosi',
      'Pando'
    ];
    _.forEach(cities, function(c) {
      var city = new City();
      city.set({
        name: c,
        createdAt: new Date(),
        totalListings: 0
      });
      city.generateSlug();
      if (city.validate()) {
        city.save();
      }
    });
  }
});
Running the seeds command.

All of our seed instructions are in a Meteor method, so you can run it like this:

$ meteor shell
> Meteor.call("Database.seed")

Run your meteor shell, then invoke your Meteor method. Simple.


That's all you need to seed your database with initial data. As an extra here are what our models look like:

Categories = new Mongo.Collection("categories");

Category = Astro.Class({  
  name: 'Category',
  collection: Categories,
  fields: {
    name: {
      type: 'string',
      validator: [
        Validators.required(null, "Type in a name for your Category."),
        Validators.unique(null, "A category with this name already exists."),
        Validators.minLength(4, "Your category name has to be at least 4 letters."),
        Validators.maxLength(100, "Your category name can't be bigger than 100 letters.")
      ]
    },
    slug: {
      type: 'string',
      validator: [
        Validators.unique(null, "A category with this name already exists.")
      ]
    },
    createdAt: {
      type: 'date',
      validator: [
        Validators.required(),
      ]
    },
    totalListings: {
      type: 'number'
    }
  },
  methods: {
    updateListingCount() {
      Meteor.call("Category.updateListingCount", this._id);
    },

    generateSlug: function() {
      var self = this;
      Meteor.call("Helpers.generateSlug", this.name, function(error, response) {
        self.set('slug', response);
      });
    }
  }
});

And our City model:

Cities = new Mongo.Collection("cities");

City = Astro.Class({  
  name: 'City',
  collection: Cities,
  fields: {
    name: {
      type: 'string',
      validator: [
        Validators.required(null, "Type in a name for your City."),
        Validators.unique(null, "A city with this name already exists."),
        Validators.minLength(4, "Your city name has to be at least 4 letters."),
        Validators.maxLength(100, "Your city name can't be bigger than 100 letters.")
      ]
    },
    slug: {
      type: 'string',
      validator: [
        Validators.unique(null, "A city with this name already exists.")
      ]
    },
    createdAt: {
      type: 'date',
      validator: [
        Validators.required(),
      ]
    },
    totalListings: {
      type: 'number'
    }
  },
  methods: {
    updateListingCount() {
      Meteor.call("City.updateListingCount", this._id);
    },

    generateSlug: function() {
      var self = this;
      Meteor.call("Helpers.generateSlug", this.name, function(error, response) {
        self.set('slug', response);
      });
    }
  }
});

How to identify memory issues in Rails 4 using the Oink gem

$
0
0

So your application’s memory usage increase dramatically and you don’t know why.

We’ve all been there.

This guide assumes you’re using Rails 4, Heroku and Papertrail to save logs. Honestly all you need are the log files anyways.


Install the Oink gem for your Rails application.

gem'oink'

In both, production.rb and development.rb, make sure you have the Oink middleware set up to save memory usage information directly to our logs.

config.middleware.use(Oink::Middleware,:logger=>Hodel3000CompliantLogger.new(STDOUT))

That Hodel3000CompliantLogger bit is very important! Oink can only read lines formatted using that logger format.

Let your app do it’s thing for a day or two - then download the huge logs you have amassed. This will give you real insight to what pages your users are hitting and how memory is moving around.

Download your logs from Papertrail, and massage it into something Oink can understand by removing the unnecessary log lines.

$ cat papertrail.tsv | cut -f 10- | grep 'rails\['> production-oink.log

Now feed that file into Oink and you’re all set.

$ oink --threshold=0 production-oink.log

Example output:

sergiotapia at Sergios-iMac in ~/Work/App
$ oink --threshold=0 production-oink.log 
---- MEMORY THRESHOLD ----
THRESHOLD: 0 MB

-- SUMMARY --
Worst Requests:
1. May 03 03:51:10, 356004 KB, users#show
2. May 03 03:16:07, 311312 KB, users#show
3. May 03 18:48:34, 304216 KB, users#show
4. May 03 08:17:27, 292592 KB, users#show
5. May 03 02:49:16, 288608 KB, users#show
6. May 03 06:43:21, 236604 KB, users#show
7. May 03 03:08:15, 235912 KB, users#show
8. May 03 00:02:33, 233092 KB, users#show
9. May 03 23:43:51, 232632 KB, users#show
10. May 03 22:01:59, 231676 KB, users#show

Welcome to Jekyll!

$
0
0

You’ll find this post in your _posts directory. Go ahead and edit it and re-build the site to see your changes. You can rebuild the site in many different ways, but the most common way is to run jekyll serve, which launches a web server and auto-regenerates your site when a file is updated.

To add new posts, simply add a file in the _posts directory that follows the convention YYYY-MM-DD-name-of-post.ext and includes the necessary front matter. Take a look at the source for this post to get an idea about how it works.

Jekyll also offers powerful support for code snippets:

defprint_hi(name)puts"Hi, #{name}"endprint_hi('Tom')#=> prints 'Hi, Tom' to STDOUT.

Check out the Jekyll docs for more info on how to get the most out of Jekyll. File all bugs/feature requests at Jekyll’s GitHub repo. If you have questions, you can ask them on Jekyll Talk.

How to use Twitter Bootstrap from NPM in your Meteor application?

$
0
0

Here’s how you can use Twitter Bootstrap directly from NPM, an arguably better updated source than something like Atmosphere.

Make sure you’re using the SCSS compilation package:

meteor add fourseven:scss

To make this work, you must use the latest version (at the time of this writing) of Meteor: 1.3.2.2

How can you update your application? Go to your application folder and run:

$ meteor update --release 1.3.2.2

Let’s install Twitter Bootstrap.

https://www.npmjs.com/package/bootstrap-sass

Install the package to your Meteor application directory. This will place the styles in your node_modules folder.

$ npm install bootstrap-sass --save

Then you can easily import the styles in your main.scss stylesheet.

For example, in myapp/client/stylesheets/main.scss:

@import"{}/node_modules/bootstrap-sass/assets/stylesheets/_bootstrap.scss";.header{color:#333;}

How to pair bluetooth headset S530 with an iPhone?

$
0
0

Recently I bought a bluetooth headset called S530 and was having a lot of trouble with it’s very poor user manual.

Bluetooth Headset S530

Here’s how you can pair the headset with your iPhone or really any bluetooth device.


Press and hold the button! You’ll hear “Power on”, then if you keep the button pressed you’ll hear “Pairing”, and voila, you should see the device on your phone under the Bluetooth menu.

Hope this helps!

Background processing using Elixir, GenServer and the Erlang queue class


Using Pundit to protect your Rails API.

Using Webpack and React in a Rails application.

Using Mobx and React to build an instant search.

Javascript Closures — what are they used for? Should you care?

Javascript Tip: Don’t bind your functions, use a closure

Viewing all 38 articles
Browse latest View live