Skip to content

Instantly share code, notes, and snippets.

@rahul8590
rahul8590 / prefix.py
Created December 30, 2014 02:08
CodeEval Challenge 7 (prefex solving )
#!/bin/python
from __future__ import division
import operator
class Slack:
def __init__(self):
self.items = []
@rahul8590
rahul8590 / splitstring.py
Last active August 29, 2015 14:08
Breaking of a String CLR 5-9
#!/bin/python
import sys
def splitstr(n,cut_list):
if len(cut_list) == 0:
return [0,[]]
min_positions = []
min_cost = sys.maxint
for k in cut_list:
left_split = [ x for x in cut_list if x < k]
@rahul8590
rahul8590 / install.sh
Created April 20, 2014 07:14
Planet Lab Installation Shell Script
#!/bin/bash
wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/7u55-b13/jdk-7u55-linux-i586.tar.gz
wget http://apache.mirrors.pair.com//cassandra/2.0.7/apache-cassandra-2.0.7-bin.tar.gz
tar -xvf jdk-7u55-linux-i586.tar.gz\?AuthParam\=1397971823_52e8ace10923c9f8a5705faca17b4719
gunzip apache-cassandra-2.0.7-bin.tar.gz
@rahul8590
rahul8590 / ScriptEngineSample.java
Created April 8, 2014 06:18
Script Engine Which is currently supposed to be running lua code .
import javax.script.ScriptEngine;
import javax.script.ScriptEngineFactory;
import javax.script.ScriptEngineManager;
import org.luaj.vm2.*;
import org.luaj.vm2.lib.jse.*;
import javax.script.CompiledScript;
import javax.script.Bindings;
import javax.script.Compilable;
public class ScriptEngineSample {
@rahul8590
rahul8590 / factorize.py
Created February 28, 2014 19:39
Easiest Way to factorize in Python
'''
divmod() function is a handy tool in such cases.
>>> divmod(10,2)
(5, 0)
'''
r = set()
def factorize(n):
for i in range(1,int(n ** 0.5) + 1 ):
div,mod = divmod(n,i)
if mod == 0:
  1. General Background and Overview
@rahul8590
rahul8590 / problem_calc.py
Created December 4, 2013 09:26
Small Snippet used to calculate and plot the data set
xl = {0:0.329,4:0.632,6:0.795,8:0.917,10:0.981}
sum = []
for n in range(1,21):
a1 = xl[4]**n - xl[0]**n
a2 = xl[6]**n - xl[4]**n
a3 = xl[8]**n - xl[6]**n
a4 = xl[10]**n - xl[8]**n
a5 = 1 - xl[10]**n
print "the intermediate values are " ,a1,a2,a3,a4,a5
sum.append(a1*0 + a2*1 + a3*2 + a4*5.5 + a5*11)
@rahul8590
rahul8590 / 0_reuse_code.js
Created October 18, 2013 15:49
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@rahul8590
rahul8590 / hapijs.js
Created October 9, 2013 06:24
Simple file handling structure using Hapijs . I am writing this out of pure frustration since, the website fails to cover the cases for static file handling.
var Hapi = require('hapi');
// Create a server with a host and port
var server = Hapi.createServer('localhost', 8000);
server.route([
{
method: 'GET',
path: '/{path*}',
@rahul8590
rahul8590 / openmp1.cpp
Created July 13, 2013 17:42
OpenMp program. To compile this in C++ $ g++ table.cpp -fopenmp -o table #this assumes openmp is installed in your system. $ export OMP_NUM_THREADS=4 #set the number of threads needed for you.
#include<iostream>
#include <cmath>
int main()
{
const int size = 256;
double sinTable[size];
#pragma omp parallel
{
printf("hello\n");