Skip to content

Instantly share code, notes, and snippets.

View mehulkar's full-sized avatar

Mehul Kar mehulkar

View GitHub Profile
### Keybase proof
I hereby claim:
* I am mehulkar on github.
* I am mehulkar (https://keybase.io/mehulkar) on keybase.
* I have a public key whose fingerprint is 0124 35B0 BA24 1473 594F 5712 8565 B49E 13F9 BF48
To claim this, I am signing this object:
@mehulkar
mehulkar / gist:dca4b66e9e2e25f6f591
Last active August 29, 2015 14:07
ActiveModelSerializers

I always forget all the different ways of serializing associations things, so putting down notes:

has_many

class AuthorSerializer < ActiveModel::Serializer
  has_many :posts
emd
# Inspired by @mrmrs http://designbytyping.com/2014/10/17/cloning-repos/
user="mehulkar"
# curl the pages directly instead of saving
# the urls to a txt file first
for page in {1..3}; do
curl "https://api.github.com/users/$user/repos?page=$page&per_page=100" >> repos.json
done
@mehulkar
mehulkar / gist:6964b68b3e2302e81f9b
Last active August 29, 2015 14:08
git precommit hook for rspec
#!/usr/bin/env bash
# Add this file to .git/hooks/pre-commit
# and make it executable.
# 1. greps the repo for "focus: true"
# 2. counts number of results
# 3. Strips the whitespace from the resulting number string
num=$(git grep "focus: true" | wc -l | xargs)
@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 / 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;