Skip to content

Instantly share code, notes, and snippets.

#I have written a small snippet to open a given url which doest open on first time and i need to
#Keep refreshing it.
import webbroswer
import time
url = "the url u want to enter"
for i in range(5):
webbrowser.open_new_tab(url)
@rahul8590
rahul8590 / rusmulti.cpp
Created March 8, 2013 16:49
Its a simple implementation of Russians Peasant multiplication algorithm.
#include<iostream>
using namespace std;
int main()
{
int a,b,c=0;
cin >> a >> b;
while(a)
{
if(a&1)
@rahul8590
rahul8590 / lettercount.py
Created February 27, 2013 13:50
Have the function LetterCountI(str) take the str parameter being passed and return the first word with the greatest number of repeated letters. For example: "Today, is the greatest day ever!" should return greatest because it has 2 e's (and 2 t's) and it comes before ever which also has 2 e's. If there are no words with repeating letters return …
def LetterCountI(str):
l = []
index = 0
for k,i in enumerate(str.split(' ')):
d = {}
for j,c in enumerate(i):
d[c] = d.get(c,0) + 1
d = {key: value for key, value in d.items() if value != 1}
if (not l):
@rahul8590
rahul8590 / repeated.py
Created February 27, 2013 13:01
If you want a dictonary consisting of repeating characters only for a given string in python.
# To get a dictionary of repeated characters in a given string
some_dict = {}
for i,c in enumerate("testing"):
some_dict[c] = some_dict.get(c,0) + 1
some_dict = {key: value for key, value in some_dict.items() if value != 1}
f = open('data.txt' ,'r')
import re
d = {}
title = ""
for i in f:
j = i.split("\n")
if j[0] != '#' and j[0] != '':
if re.match('#',j[0]):
title = j[0]
title_info = []
@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: