Skip to content

Instantly share code, notes, and snippets.

View brainix's full-sized avatar
💻
Designed by Apple in California

Rajiv Bakulesh Shah brainix

💻
Designed by Apple in California
View GitHub Profile
@brainix
brainix / analytics.coffee
Last active September 7, 2018 15:50
CoffeeScript for Google Analytics
class GoogleAnalytics
@init: (webPropertyId) ->
@_initQueue webPropertyId
scriptTag = @_createScriptTag()
@_injectScriptTag scriptTag
true
@_initQueue: (webPropertyId) ->
window._gaq ?= []
window._gaq.push ['_setAccount', webPropertyId]
@brainix
brainix / models.rb
Created January 4, 2013 02:03
Prevent DataMapper resources from being destroyed
require 'data_mapper'
module Appends
module InstanceMethods
# This module contains methods that we'll make available as instance
# methods on DataMapper resources.
def vomit
throw :halt
end
@brainix
brainix / jquery.haml
Last active December 11, 2015 21:28
Haml use jQuery 1.x for old IE, 2.x for all other browsers
- jquery_1x = 'jquery-1.11.0-beta2.min.js'
- jquery_2x = 'jquery-2.1.0-beta2.min.js'
/[if lt IE 9]
-# The user is on an ancient browser. Load jQuery 1.x from the CDN.
%script{src: "http://code.jquery.com/#{jquery_1x}"}
-# If loading jQuery from the CDN fails, then load our local copy.
:javascript
window.jQuery || document.write(
@brainix
brainix / deprecated.rb
Created February 27, 2013 07:33
Deprecate routes (URLs) in Sinatra
['/old', '/old2'].each do |path|
get path do
# Deprecated: Please call `/new` instead.
warn "[DEPRECATION] `#{path}` is deprecated. Please call `/new` instead."
url = '/new'
url += "?#{request.query_string}" unless request.query_string.empty?
redirect to(url), 301
end
end
@brainix
brainix / bidder.conf
Last active December 16, 2015 03:09
RTB bidder Nginx config
# /etc/nginx/conf.d/bidder.conf
upstream unicorn {
server unix:/srv/bidder/shared/unicorn.sock fail_timeout=0;
}
server {
listen 80 default deferred;
@brainix
brainix / nginx.conf
Created April 13, 2013 00:40
Nginx config
# /etc/nginx/nginx.conf
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log;
@brainix
brainix / install_do_postgres.sh
Last active January 3, 2016 13:19
Install the do_postgres gem with Postgres.app
gem install do_postgres -- \
--with-pgsql-server-dir=/Applications/Postgres.app/Contents/Versions/9.3 \
--with-pgsql-server-include=/Applications/Postgres.app/Contents/Versions/9.3/include/postgresql/server
@brainix
brainix / spool.tv-api.md
Last active August 29, 2015 14:11
The spool.tv Public REST API

Public REST API

Overview

spool.tv is a music video preview website. We aggregate a lot of data about songs, artists, and music genres. If you build anything with our API, we’d love to hear about it! Or if you need some help, please contact us: [email protected] Happy hacking!

Paths

We identify songs, artists, and genres by paths. Paths are lowercased, hyphenated, unique identifiers that correspond to the names of songs, artists, and genres. If you’d like to query for a song, artist, or genre and you don’t know its path, your best bet is to use our search API endpoint. In the search result, you’ll find the song path as path, the artist path as artist_path, and the genre path as genre_path.

Metrics (popularity and freshness)

We score each music video preview according to how popular it is cumulatively (popularity), and how trending it is today (freshness). Lastly, we normalize these scores

# XXX -- Top level review comments:
#
# * Nice exception recovery and logging.
#
# * Please cleanup code formatting.
# This is a little rough on my eyes.
#
# * Should we use this as template for other
# short network element scripts?
#
from nettools import NetworkElement
with NetworkElement('171.0.2.45') as ne:
for route in ne.routing_table:
print '%15s -> %s' % (route.name, route.ipaddr)