Skip to content

Instantly share code, notes, and snippets.

View utsengar's full-sized avatar
🚀
Hustling.

Utkarsh Sengar utsengar

🚀
Hustling.
View GitHub Profile
@utsengar
utsengar / wiki_objc_client.m
Last active August 29, 2015 13:56
wiki client in objc
//
// Wikipedia.m
// yoda
//
// Created by Utkarsh Sengar on 2/9/14.
// Copyright (c) 2014 area42. All rights reserved.
//
#import "Wikipedia.h"
#import "AFNetworking.h"
@utsengar
utsengar / haversine.py
Created March 23, 2014 07:00
Find distance between two lat/lon
from math import radians, cos, sin, asin, sqrt
def haversine(lon1, lat1, lon2, lat2):
"""
Calculate the great circle distance between two points
on the earth (specified in decimal degrees)
"""
# convert decimal degrees to radians
lon1, lat1, lon2, lat2 = map(radians, [lon1, lat1, lon2, lat2])
@utsengar
utsengar / check_battery.sh
Created May 5, 2015 04:17
Check Battery health for a Mac (result in %, should be 100% for a brand new mac)
echo $(ioreg -l -n AppleSmartBattery -r | grep MaxCapacity | awk '{print $3}') / $(ioreg -l -n AppleSmartBattery -r | grep DesignCapacity | awk '{print $3}') \* 100 | bc -l
@utsengar
utsengar / pom.xml
Created August 20, 2015 23:55
Simple maven assembly example (which works)
<!-- Source: http://www.mkyong.com/maven/create-a-fat-jar-file-maven-assembly-plugin -->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mkyong.core.utils</groupId>
<artifactId>dateUtils</artifactId>
<packaging>jar</packaging>
class Main{public static void main(String...args){\u0066or(int
\u0020$:"vÌÈÊ\"¤¾Àʲ¬Æ\"v¤Î¤\"²¤¨¸¬Æ".to\u0043h\u0061rArray()
)System./*goto/*$/%\u0126//^\u002A\u002Fout.print((char)(($>>
+(~'"'&'#'))+('<'>>('\\'/'.')/\u002Array.const(~1)\*\u002F)));}}
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
@utsengar
utsengar / bootstrap.sh
Created June 2, 2011 19:00 — forked from anonymous/bootstrap.sh
Django on Heroku with Postgres, Celery and Sentry
virtualenv --no-site-packages .
source bin/activate
bin/pip install Django psycopg2 django-sentry
bin/pip freeze > requirements.txt
bin/django-admin.py startproject mysite
cat >.gitignore <<EOF
bin/
include/
lib/
EOF
@utsengar
utsengar / map_reduce.py
Created June 6, 2011 08:31
map/reduce - Python
## {{{ http://code.activestate.com/recipes/577676/ (r9)
from collections import namedtuple
from math import fsum
def map_reduce(data, mapper, reducer=None):
'''Simple map/reduce for data analysis.
Each data element is passed to a *mapper* function.
The mapper returns key/value pairs
or None for data elements to be skipped.
@utsengar
utsengar / singelton_classloader.java
Created June 14, 2011 04:13
fix singelton issues when using multiple classloaders
private static Class getClass(String classname) throws ClassNotFoundException {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
if(classLoader == null)
classLoader = Singleton.class.getClassLoader();
return (classLoader.loadClass(classname));
}
}
//Source: http://snehaprashant.blogspot.com/2009/01/singleton-pattern-in-java.html
/** The preceding method tries to associate the classloader with the current thread; if that
@utsengar
utsengar / osx
Created September 8, 2011 23:59
osx defaults by mathiasbynens
Source: https://github.com/mathiasbynens/dotfiles/blob/master/.osx
# Enable full keyboard access for all controls (e.g. enable Tab in modal dialogs)
defaults write NSGlobalDomain AppleKeyboardUIMode -int 3
# Enable the 2D Dock
defaults write com.apple.dock no-glass -bool true
# Disable menu bar transparency
defaults write -g AppleEnableMenuBarTransparency -bool false