Skip to content

Instantly share code, notes, and snippets.

View mehulkar's full-sized avatar

Mehul Kar mehulkar

View GitHub Profile
@dnf
dnf / git-shove
Created November 15, 2013 21:50
Implementation of git shove we use at Medium
#!/bin/sh
if [ "master" = "$(git rev-parse --abbrev-ref HEAD)" ] ; then
echo "\033[1;31mYou may not shove master\033[0m"
exit 1;
fi
exec git push --force origin HEAD
@roldershaw
roldershaw / imsg
Last active January 5, 2025 10:33
Send iMessages from the command line using Bash and AppleScript
#!/bin/bash
if [ -z "$1" ] || [ -z "$2" ] ; then
echo "Usage: imsg [address] [message]"
else
/usr/bin/osascript -e 'tell application "Messages"
send "'"$2"'" to buddy "'"$1"'" of service "E:[email protected]"
end tell'
echo "Sent"
fi
a = 1 # one
b = a - 1 # zero
(b..a).include?(a) #=> true
(b..a).include?(a.to_f) #=> true
(b..a).include?(0.5) #=> true
a = DateTime.now # now
b = a - 1 # 24 hours ago
(b..a).include?(a) #=> true
(b..a).include?(a.to_date) #=> false
import json
import urllib
import urllib2
import time
""" Nike plus activity log
https://developer.nike.com
Output:
-- May --
@machty
machty / new-router-examples.md
Last active April 16, 2020 22:03
How to do cool stuff with the new Router API
@gpoitch
gpoitch / google_analytics_mixin.js
Last active December 16, 2015 16:40
A Google Analytics mixin for an Ember application controller. Sends a page view whenever the currentPath (url) changes. Normalizes the page url for both history and hash location routers.
Ember.GoogleAnalytics = Ember.Mixin.create({
trackPageView: function() {
if(!Ember.isNone(ga)) {
Ember.run.next(function() {
var loc = window.location,
page = loc.hash ? loc.hash.substring(1) : loc.pathname + loc.search;
ga('send', 'pageview', page);
});
}
class VotesController < ApplicationController
  def create
    @vote = Vote.find_or_initialize_by_submitted_by_ip(request.remote_ip)
    @vote.update_attributes(params[:vote]) if !@vote.has_user?(session[:user_id])
    render json: @vote
  end
end

class Vote &lt; ActiveRecord::Base
@knzai
knzai / uri_validator.rb
Last active December 14, 2015 16:09 — forked from bluemont/url_validator.rb
Totally untested, just forked and tweaked for discussion
require 'addressable/uri'
#Accepts options[:message] and options[:allowed_protocols]
class UriValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
uri = parse_uri(value)
if !uri
record.errors[attribute] << generic_failure_message
elsif !allowed_protocols.include?(uri.scheme)
@stevekane
stevekane / assetfileexample
Created January 31, 2013 23:39
example of Assestfile to compile templates
require 'rake-pipeline-web-filters'
input "static" do
output "static/js/src"
#compile handlebars templates into Ember.TEMPLATES
match "coffee/templates/**/*.handlebars" do
handlebars
concat "templates.js"
end
end
@nathansmith
nathansmith / check_all.js
Last active December 11, 2015 12:38
For when you need a master checkbox, that will cause others to be checked.
/*
Use like this (or with <dl>, <ol>, <table>)...
<ul>
<li>
<input type="checkbox" class="check-all" />
</li>
<li>
<input type="checkbox" />
</li>