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 / EncodeBased64Binary.java
Created October 11, 2011 00:27
Encode a file to base64 binary in Java
import org.apache.commons.codec.binary.Base64;
private String encodeFileToBase64Binary(String fileName)
throws IOException {
File file = new File(fileName);
byte[] bytes = loadFile(file);
byte[] encoded = Base64.encodeBase64(bytes);
String encodedString = new String(encoded);
@utsengar
utsengar / gist:1329947
Created November 1, 2011 04:32
Object dump using gobjdump on Mac OSX
1. Write a hello hello world c
main( )
{
printf("Hello World\n");
}
2. Compile it: gcc hello.c
Bonus: `gcc -Wall -save-temps hello.c -o hello` will give you extra stuff like:
@utsengar
utsengar / Sleepsort.java
Created November 9, 2011 21:59
Java version of Sleep sort
/**
* For fun.
* Inspiration: http://dis.4chan.org/read/prog/1295544154
* @author zengr
*
*/
public class Sleepsort {
private static int[] inputArray = { 3, 1, 2, 1, 181, 10};
@utsengar
utsengar / MonitorExample.java
Created November 17, 2011 08:19 — forked from bbejeck/MonitorExample.java
Sample Code for Guava Monitor Blog
import com.google.common.util.concurrent.Monitor;
import java.util.concurrent.atomic.AtomicInteger;
/**
* Created by IntelliJ IDEA.
* User: bbejeck
* Date: 11/11/11
* Time: 10:01 PM
*/
@utsengar
utsengar / bothaiyanaar.py
Created December 7, 2011 09:13 — forked from bicepjai/bothaiyanaar.py
bothaiyanaar theorem
#! /usr/bin/python
import math
def pytha(a,b):
return math.sqrt(pow(a,2) + pow(b,2))
def botha(a,b):
return (float(a) - float(a/8) + float(b/2))
@utsengar
utsengar / Sync_Async_loading_handlebars.js
Created April 2, 2012 20:41
synchronous and asynchronous loading of handlebars templates
/*
* This decorates Handlebars.js with the ability to load
* templates from an external source, with light caching.
*
* To render a template, pass a closure that will receive the
* template as a function parameter, eg,
* T.render('templateName', function(t) {
* $('#somediv').html( t() );
* });
* Source: https://github.com/wycats/handlebars.js/issues/82
@utsengar
utsengar / gmail_analyze.py
Created May 24, 2012 07:55
Analyze gmail data
#Install scipy: http://glowingpython.blogspot.it/2012/05/analyzing-your-gmail-with-matplotlib.html
from imaplib import IMAP4_SSL
from datetime import date,timedelta,datetime
from time import mktime
from email.utils import parsedate
from pylab import plot_date,show,xticks,date2num
from pylab import figure,hist,num2date
from matplotlib.dates import DateFormatter
@utsengar
utsengar / CassandraToSolrETL.java
Created June 21, 2013 00:16
DSE wordcount M/R job
package com.rl.hadoopjobs;
import java.io.IOException;
import java.net.URI;
import java.util.StringTokenizer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
@utsengar
utsengar / center_div.js
Created July 29, 2013 04:58
Center any div on page (think google.com's search box)
// $(element).center();
jQuery.fn.center = function ()
{
this.css("position","absolute");
this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
return this;
}
@utsengar
utsengar / schema.xml
Last active December 20, 2015 17:18
Solr's schema.xml
<?xml version="1.0" encoding="UTF-8" ?>
<schema name="prodinfo" version="1.1">
<types>
<fieldType name="long" class="solr.TrieLongField" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>
<fieldType name="string" class="solr.StrField"/>
<fieldType name="text_general" class="solr.TextField" positionIncrementGap="100">
<analyzer type="index">
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" />
<filter class="solr.LowerCaseFilterFactory"/>