Skip to content

Instantly share code, notes, and snippets.

View kirang89's full-sized avatar

Kiran Gangadharan kirang89

View GitHub Profile
@kirang89
kirang89 / gist:3603209
Created September 2, 2012 19:00 — forked from rodionmoiseev/gist:2484934
Setting up Play 2.0 in build.gradle
apply plugin: 'java'
apply plugin: 'scala'
// For those using Eclipse or IntelliJ IDEA
apply plugin: 'eclipse'
apply plugin: 'idea'
def findPlay20(){
def pathEnvName = ['PATH', 'Path'].find{ System.getenv()[it] != null }
for(path in System.getenv()[pathEnvName].split(File.pathSeparator)){
for(playExec in ['play.bat', 'play.sh', 'play']){
@kirang89
kirang89 / Serializer.java
Created October 13, 2012 21:23
Serializing and deserializing an object in Java
public class Serializer {
public static byte[] serialize(Object obj) throws IOException {
ByteArrayOutputStream b = new ByteArrayOutputStream();
ObjectOutputStream o = new ObjectOutputStream(b);
o.writeObject(obj);
return b.toByteArray();
}
public static Object deserialize(byte[] bytes) throws IOException, ClassNotFoundException {
ByteArrayInputStream b = new ByteArrayInputStream(bytes);
@kirang89
kirang89 / branchClone.sh
Created January 17, 2013 16:32
Clone a particular branch of a repo
mkdir $BRANCH
cd $BRANCH
git init
git remote add -t $BRANCH -f origin $REMOTE_REPO
git checkout $BRANCH
@kirang89
kirang89 / octopress_contribute.sh
Last active December 11, 2015 09:28
Contribute to your existing octopress blog
$ git clone [email protected]:username/username.github.com.git
$ cd username.github.com
$ git checkout source
$ mkdir _deploy
username.github.com$ cd _deploy
username.github.com/_deploy$ git init
username.github.com/_deploy$ git remote add origin [email protected]:username/username.github.com.git
username.github.com/_deploy$ git pull origin master
@kirang89
kirang89 / timer.py
Created February 13, 2013 14:24
Using lambda to create a timer in python
import time
start = time.time()
tic = lambda: 'at %1.1f seconds' % (time.time() - start)
#
# Testing multithreaded operations using concurrent.futures.
#
# The concurrent.futures library was introduced in Python 3.2, but if you want to run it in 2.x,
# you can download the backport of this library from http://pypi.python.org/pypi/futures
#
from concurrent.futures import ThreadPoolExecutor
import requests
@kirang89
kirang89 / tuple_list_sort.py
Created March 26, 2013 09:27
Sorting a list of tuples based on either value in the tuple
from operator import itemgetter
a = [('Ant', 1), ('Elephant', 2), ('Cow', 3), ('Deer', 4)]
print "List sorted according to animal name: ", sorted(a, key=itemgetter(0,1))
print "List sorted according to number: ", sorted(a, key=itemgetter(1,0))
@kirang89
kirang89 / sublime_settings.json
Last active December 15, 2015 17:28
Custom Sublime settings
{
"color_scheme": "Packages/User/Tomorrow-Night.tmTheme",
"detect_slow_plugins": false,
"draw_white_space": "all",
"find_selected_text": true,
"fold_buttons": false,
"folder_exclude_patterns":
[
".svn",
".git",
@kirang89
kirang89 / datetime_safe.py
Created April 18, 2013 08:24
Better datetime representation
import datetime
datetime.datetime.utcnow().replace(microsecond=0)
#Example Output: datetime.datetime(2013, 4, 18, 8, 23, 29)
@kirang89
kirang89 / dict_merge.py
Created April 24, 2013 20:34
Merging 2 dicts
#!/usr/bin/env python
d1 = dict(a=1, b=2, c=3)
d2 = dict(d=4, e=5, d=6)
dict_new = dict(d1, **d2)
print dict_new