Skip to content

Instantly share code, notes, and snippets.

  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");
@rahul8590
rahul8590 / simple_sampling.py
Last active December 19, 2015 10:59
In order to sample continuous stream of data (numbers). We need to pick up number whos probability of choosing is 1/ (n+1).
#sl is a sample list of numbers which is contiguously getting updated.
import random
def simple_sample(sl):
for x,y in enumerate(sl,1):
if random.random() < 1.0 / x:
sample_data = y
return sample_data
@rahul8590
rahul8590 / python_scale.py
Created June 20, 2013 07:11
This is the python program for the scale.cpp program.
#Run will execute the run function on scale.cpp
from ctypes import cdll
lib = cdll.LoadLibrary('./libscale.so')
class Foo(object):
def __init__(self):
self.obj = lib.Foo_new()
def run(self):
lib.Foo_run(self.obj)
f = Foo()
@rahul8590
rahul8590 / scale.cpp
Created June 20, 2013 07:05
The Scale program uses the Boost::ASIO libraries in order to execute the functions in async fashion. It also uses mutiple threads to have io.services run in each of them. I have Interfacing the C++ code with C wrapper .
#include <boost/asio.hpp>
#include <boost/thread.hpp>
#include <iostream>
class Foo {
@rahul8590
rahul8590 / sample_asio.cpp
Created June 18, 2013 14:42
Just goofing around Boost ASIO library . The following is the first attempt to mess with it.
// You also need to link pthread and boost_system in order to run it. The following will be the command , if you are too lazy to
// type
// $ g++ sample_asio.cpp -o asio -lpthread -lboost_system
//
#include <boost/asio.hpp>
#include <iostream>
using namespace std;
""" This Small snippet will list the set of functions present in the module
__doc__
__file__
__name__
__package__
information about the module.
Hello module used in here is a simple py file for Bottle framework.
"""