Skip to content

Instantly share code, notes, and snippets.

@raghothams
raghothams / mtp-android-mount
Last active December 19, 2015 10:19
Mount & unmount android 4+ on linux
mkdir ~/android
mtp-detect
mtpfs ~/android
#to unmount
fusermount -u ~/android
@raghothams
raghothams / GsonConvertor.java
Created July 8, 2013 17:26
Parse complex JSON string into Java objects using GSON
String jsonStr = "{ \"debug_info\" : [], \"html_attributions\" : [], \"results\" : [ { \"geometry\" : { \"location\" : { \"lat\" : 12.9774180, \"lng\" : 77.71423799999999 } }, \"icon\" : \"http://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png\", \"id\" : \"742446507e37ea90df8389717e4835fe659183ed\", \"name\" : \"The Oriental Pavilion\", \"reference\" : \"CoQBdAAAAO8vSS9emj1nHgkl6zfX2RBC2HqMJEUPMFHH3HkCxwNy4Sa8Y9CynZo7sozZV5CPEDMvvg5GMFQBPxAdPX0oDMzOJhvqDq_wr2eWIlFKV7fB2Inm1GWj0hCMOsLy3zD8RVAMN74JIsHyR-xQWulDRwsxxQ-bhbmBzCYFfxTKd-I1EhDBAkzm4xIWEEIdmWriBsgyGhStZUB2SzvEb2j6nuuzjsMxHHzNzg\", \"types\" : [ \"restaurant\", \"food\", \"establishment\" ], \"vicinity\" : \"134-136, Fortune Select Trinity, ITPL Main Road, EPIP Area, Whitefield, Bangalore\" }, { \"geometry\" : { \"location\" : { \"la
@raghothams
raghothams / mongobackup.sh
Created July 31, 2013 05:00
shell script to backup DB from mongo
#!/bin/bash
cd ~/backups
folder=$(date +%Y%m%d)
mkdir $folder && cd $folder
mongodump -d sharurl
tar -cvf dump.tar.gz ./dump
rm -rf ./dump
@raghothams
raghothams / mongobackup.sh
Created July 31, 2013 05:01
shell script to backup DB from mongo
#!/bin/bash
cd ~/backups
folder=$(date +%Y%m%d)
mkdir $folder && cd $folder
mongodump -d sharurl
tar -cvf dump.tar.gz ./dump
rm -rf ./dump
from flask import request, make_response,
def any_response(data):
ALLOWED = ['http://localhost:8888']
response = make_response(data)
origin = request.headers['Origin']
if origin in ALLOWED:
response.headers['Access-Control-Allow-Origin'] = origin
return response
import datetime
import time
# some datetime object
dt = datetime.datetime.now()
# get the seconds since epoch for that datetime
print time.mktime(dt.timetuple())
@raghothams
raghothams / .gitattributes
Created August 23, 2013 09:28
Git eol markers
* text=auto
* text eol=crlf
*.html text eol=crlf
*.css text eol=crlf
*.js text eol=crlf
*.json text eol=crlf
@raghothams
raghothams / flash-image
Created November 15, 2013 05:39
Flash Google factory images
adb reboot bootloader
fastboot flash bootloader bootloader-hammerhead-HHZ11d.img
fastboot reboot-bootloader
fastboot flash radio radio-hammerhead-M8974A-1.0.25.0.17.img
fastboot reboot-bootloader
fastboot -w update image-hammerhead-krt16m.zip
fastboot reboot-bootloader
@raghothams
raghothams / from-dos.sh
Created January 8, 2014 16:39
Convert Dos to unix eol. Remove ^M
#!/bin/bash
cd ${1}
for f in `find .*rc`; do
echo $f
tr -d '\15\32' < $f > $f.tr
mv $f.tr $f
done
@raghothams
raghothams / py-unicode.py
Created January 21, 2014 18:40
Python Unicode conversion error
# Solving unicode to ascii conversion error
str1 = '\xc6\xe5\t\xc5\xba\xc6;\xe4y\xdf8\xd8U\xcb\xff\xaaT@\r&\x8c\xbd\x95v'
print type(str1)
str_in_ascii = str1.encode('base-64')
print type(str_in_ascii)