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
#!/usr/bin/env python3
import sys
# Map the uppercase letters forwards:
_MAPPING = {
'Q': 'P',
'W': 'O',
@brainix
brainix / rss.xml
Created June 23, 2016 03:54
iTunes top songs
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns:im="http://itunes.apple.com/rss" xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
<id>https://itunes.apple.com/us/rss/topmusicvideos/limit=200/explicit=true/xml</id><title>iTunes Store: Top Music Videos</title><updated>2016-06-22T20:09:58-07:00</updated><link rel="alternate" type="text/html" href="https://itunes.apple.com/WebObjects/MZStore.woa/wa/viewTop?cc=us&amp;id=1&amp;popId=5"/><link rel="self" href="https://itunes.apple.com/us/rss/topmusicvideos/limit=200/explicit=true/xml"/><icon>http://itunes.apple.com/favicon.ico</icon><author><name>iTunes Store</name><uri>http://www.apple.com/itunes/</uri></author><rights>Copyright 2008 Apple Inc.</rights>
<entry>
<updated>2016-06-22T20:09:58-07:00</updated>
<id im:id="1125405366">https://itunes.apple.com/us/music-video/this-is-what-you-came-for/id1125405366?uo=2</id>
# 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)
@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 / 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 / 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 / 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 / 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 / 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