Skip to content

Instantly share code, notes, and snippets.

View mehulkar's full-sized avatar

Mehul Kar mehulkar

View GitHub Profile
@mehulkar
mehulkar / gist:3177540
Last active October 7, 2015 14:18
Ruby Hash Syntax Upgrade

Convert Ruby 1.8 hash syntax into 1.9 syntax in vim E.g. :key => 'value' will become key: 'value'

:%s/:(\S+) =>/\1:/g
@mehulkar
mehulkar / gist:3179710
Created July 26, 2012 01:16
Example of Webkit Flex Box
<html>
<head>
<style type="text/css">
html, body, .container {width: 100%; height: 100%;}
.container {display: -webkit-box; -webkit-box-orient: vertical; -webkit-box-align: stretch; -webkit-box-pack: start;}
.container div {-webkit-box-flex: 1;}
</style>
</head>
<body style="width: 100%;height: 100%;">
<div class="container">
@mehulkar
mehulkar / gist:3232255
Created August 2, 2012 01:22
Flatten DS.ManyArray in Ember

Flatten a DS.ManyArray in Ember.js

Ember.ArrayProxy.prototype.flatten = Array.prototype.flatten = function() {
  var r = [];
  this.forEach(function(el) {
    r.push.apply(r, Ember.isArray(el)  ? el.flatten() : [el]);
  });
  return r;
}
@mehulkar
mehulkar / GenBoxShadow.php
Created October 5, 2012 13:13 — forked from seanlinehan/GenBoxShadow.php
Create a pure-CSS version of any image
// Do whatever you'd like with the script! Show it off, mod it up, post it places, or whatever. :)
// (If you do, I wouldn't mind a Twitter shoutout at @_slinehan when appropriate!)
$imageURL = "URL HERE";
$image = imagecreatefromjpeg($imageURL);
$width = imagesx($image);
$height = imagesy($image);
// First, let's resize the image to something manageable while maintaining aspect ratio.
<dl class="tabs pill">
<dd class="active"><a href="#pillTab1">Hotel Info</a></dd>
<dd><a href="#pillTab2">Marriott Courtyard</a></dd>
<dd><a href="#pillTab3">Homewood Suites</a></dd>
</dl>
<ul class="tabsContent">
<li id="pillTab1Tab" class="active">
Stuff
@mehulkar
mehulkar / gist:4054327
Created November 11, 2012 09:52
Ember ArrayProxy magical magic
a = Ember.A()
a.pushObject(1);
a.pushObject(2);

a.slice(-1);
// [1]
@mehulkar
mehulkar / gist:4147972
Created November 26, 2012 12:31
vertical align checkbox
ul {
    padding:0;
    display:table;
    width:100%;
    background-color:red;
}
li {
   display: table-cell;
 text-align: center;
# don't serialize comment and category records because we'll embed them into the post.
App.Adapter = DS.RESTAdapter.extend
  dirtyRecordsForBelongsToChange: (dirtySet, child, relationship) ->
    return undefined if [App.Comment, App.Category].contains child.constructor
    dirtySet.add(child)

  dirtyRecordsForHasManyChange: (dirtySet, parent, relationship) ->
    if parent.constructor == App.Post
 return undefined if ["categories", "comments"].comtains relationships.hasManyName
@mehulkar
mehulkar / gist:4388398
Last active December 10, 2015 05:29
Setting up Django/Google App Engine on a dev server

Run Django / Google App Engine on local dev server

Hopefully these instructions are useful to some Googler in the future.

  1. Install Python. Python comes with OSX. Test by typing python in terminal. If it opens a python shell, you're good to go.
  2. Install pip. easy_install pip works on OSX. This should add symlinks and add the executable to $PATH also. Technically you don't need to install pip though because every virtualenv environment comes with pip. It's easier to install virtualenv with pip though. Haven't tried easy_install virtualenv.
  3. Install virtualenv. Run pip install virtualenv. You may need to add the install directory to $PATH.
  4. Install Google AppEngine SDK from here. Drag to Applications folder. Launch it, make sure it creates symlinks. Add the google_appengine directory to the $PYTHONPATH environment variable.
  5. Navigate to your project directory. There

I can never get Rails to connect to the Postgres server in development. I'll write a fuller tutorial that explains things better later, but I can explain some really basic things first.

The issue is that osx is looking for the server socket in a default location and postgres is putting the client in a default location. Those locations are not the same.

Postgres puts the socket in /var/pgsql_socket. Or at least that is where mine is at the moment. This is configurable in a postgres.conf file. You can do a global search for this file in terminal by running sudo find / -name postgres.conf. In that file look for the line that says unix_socket_directory. You could probably edit that and tell postgres to put the socket somewhere else, but more on that later.

The client, in this case Rails, needs to know where to look for the socket. When I started my Rails server, it would crash saying it couldn't find the socket file in /tmp/.s.PGSQL.5432. So now at least I know where Rails is looking by default. I