This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <boost/asio.hpp> | |
#include <boost/thread.hpp> | |
#include <iostream> | |
class Foo { | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" 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. | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
using namespace std; | |
int main() | |
{ | |
int a,b,c=0; | |
cin >> a >> b; | |
while(a) | |
{ | |
if(a&1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = [] |
NewerOlder