Skip to content

Instantly share code, notes, and snippets.

@nitinhayaran
nitinhayaran / Gruntfile.js
Created May 18, 2013 07:38
Sample Gruntfile.js
'use strict';
var LIVERELOAD_PORT = 35729;
var lrSnippet = require('connect-livereload')({port: LIVERELOAD_PORT});
var mountFolder = function (connect, dir) {
return connect.static(require('path').resolve(dir));
};
// # Globbing
// for performance reasons we're only matching one level down:
// 'test/spec/{,*/}*.js'
@nitinhayaran
nitinhayaran / gist:5870106
Created June 26, 2013 18:36
create a input text box, similar to an existing div. Copying its text styles.
if (!window.getComputedStyle) {
window.getComputedStyle = function(el, pseudo) {
this.el = el;
this.getPropertyValue = function(prop) {
var re = /(\-([a-z]){1})/g;
if (prop === 'float') prop = 'styleFloat';
if (re.test(prop)) {
prop = prop.replace(re, function () {
return arguments[2].toUpperCase();
});
@nitinhayaran
nitinhayaran / s3-bucket-move
Created March 16, 2017 09:08 — forked from alanwill/s3-bucket-move
Move an S3 bucket to a different region
aws s3 sync s3://oldbucket s3://newbucket --source-region us-west-1 --region us-west-2
@nitinhayaran
nitinhayaran / dump_for_mysql.py
Created December 24, 2011 11:02
Quick easy way to migrate SQLite3 to MySQL
#!/usr/bin/env python
"""
sqlite3 sample.db .dump | python dump_for_mysql.py > dump.sql
cat sqllite.sql | python dump_for_mysql.py > dump.sql
"""
import re
import fileinput
def this_line_is_useless(line):
@nitinhayaran
nitinhayaran / restore.md
Created December 22, 2017 14:00
How to restore specific tables on heroku from backup

How to restore specific tables on heroku from backup

  1. Create a new database instance attached to current application
  2. Restore latest database backup on newly created database
  3. Get the connection url of this backup database. Use this URL in later sql queries.
  4. Connect to database where we have incorrect data
heroku pg:psql --app ck-api-prod
  1. On postgres prompt run following queries. This will create copy table from data in backup database.
@nitinhayaran
nitinhayaran / gist:e8fe703f79a9da4a5fe5
Last active January 4, 2019 11:19
Import heroku database
heroku pg:backups capture --app sushi
curl -o latest.dump `heroku pg:backups public-url --app sushi`
pg_restore --verbose --clean --no-acl --no-owner -j 8 [-U user_name] -d database_name latest.dump
# To copy prodcution data to staging app
heroku pg:backups restore `heroku pgbackups:url -a production-app` DATABASE -a staging-app
# Store prodcution data to staging
heroku pg:backups restore `heroku pgbackups:url -a production-app` DATABASE -a staging-app
heroku pg:backups restore b001 DATABASE_URL --app sushi
@nitinhayaran
nitinhayaran / osx.sh
Last active March 7, 2020 05:19
OSX configurations
echo "Expanding the save panel by default"
defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode -bool true
echo "Why is this not default anymore?! Enabling full keyboard access for all controls (e.g. enable Tab in modal dialogs)"
defaults write NSGlobalDomain AppleKeyboardUIMode -int 3
echo "I'm in yer computer, hax0ring yr passwords!"
echo "Requiring password immediately after sleep or screen saver begins"
defaults write com.apple.screensaver askForPassword -int 1
@nitinhayaran
nitinhayaran / smartLookEvent.js
Created February 3, 2021 13:24
smartLookEvent.js
import smartlookClient from 'smartlook-client'
const SmartLookEvent = {
initialize: () => {
const isBotUserAgent = () => {
return (
navigator &&
navigator.userAgent &&
/bot|google|baidu|bing|msn|duckduckbot|teoma|slurp|yandex|prerender/i.test(
navigator.userAgent
@nitinhayaran
nitinhayaran / peg_game.py
Created January 12, 2011 16:00
Solution for Double Square Problem in Facebook Hacker Cup 2011 Qualification Round
import sys
def find_prob(row, col, x, exempt):
size = (row,col)
arr = []
broken = exempt
for i in range(size[0]):
k = []
for j in range(size[1]*2-1):
if(i%2==0):
@nitinhayaran
nitinhayaran / flickr_urls
Last active April 29, 2023 03:59
Flickr Photo urls size suffixes along with url returned from apis
url_sq : s small square 75x75
url_q : q large square 150x150
url_t : t thumbnail, 100 on longest side
url_s : m small, 240 on longest side
url_n : n small, 320 on longest side
url_m : - medium, 500 on longest side
url_z : z medium 640, 640 on longest side
url_c : c medium 800, 800 on longest side†
url_l : b large, 1024 on longest side*
url_o : o original image, either a jpg, gif or png, depending on source format