Skip to content

Instantly share code, notes, and snippets.

@sangheestyle
sangheestyle / show_scope.sh
Created November 27, 2014 12:35
Get the scope of given class in a given file and hen show the evelution of the class via git log -L
#!/bin/bash
# Get the scope of given class in a given file
# Then show the evelution of the class via git log -L
# usage: show_scope [classname] [filename]
# cname='class HttpAuthHandler'
# fname='HttpAuthHandler.java'
cname=$1
fname=$2
begin=$(grep -n ".*$cname.*" $fname | grep -Eo "^[0-9]{1,5}")
import numpy as np
import scipy as sc
import networkx as nx
from matplotlib.colors import LogNorm
from pylab import *
def sample(n):
m = sc.misc.comb(n, 2)
r_vals = np.random.random(m)
@sangheestyle
sangheestyle / creat_and_drop_table_via_cqlsh
Last active August 29, 2015 14:08
demo: cassandra python driver. make a keyspace and insert, update, delete a repo into repos table
CREATE KEYSPACE unittest WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };
USE unittest;
CREATE TABLE commits (
id text,
path text,
author_email text,
author_name text,
subject text,
from pylab import *
import pandas as pd
df =pd.read_csv("PS04_1a.dat", names=range(1,35))
p1 = pd.DataFrame({'max': df.max(), 'mean':df.mean()})
p1.plot(marker='.', markersize=10, title='')
2 1
3 1
3 2
4 1
4 2
4 3
5 1
6 1
7 1
7 5
@sangheestyle
sangheestyle / generate_edge_list.sh
Last active August 29, 2015 14:07
Make biparted graph and projection
authors=(`git log --format='%ae' | sort -u`)
for author in ${author[*]}
do
files=(`git log --no-merges --stat --author="$author" --name-only --pretty=format:"" | sort -u`)
for file in ${files[*]}
do
echo $author $file
done
done
words1 = "pa’Daq ghah taH tera’ngan ’e".replace("’","'").split()
tags1 = "N PRO V N PRO".split()
words2 = "ja’chuqmeH rojHom neH tera’ngan".replace("’","'").split()
tags2 = "V N V N".split()
words3 = "tera’ngan qIp puq ’eg puq qIp tera’ngan".replace("’","'").split()
tags3 = "N V N CONJ N V N".split()
train = []
@sangheestyle
sangheestyle / p1-2.py
Last active August 29, 2015 14:07
nlp hw5
from collections import defaultdict
from nltk.corpus import brown
print ">>> Procssing"
word_tag = defaultdict(set)
for word, tag in brown.tagged_words():
word_tag[word].add(tag)
num_words_by_num_tags = defaultdict(int)
words_with_max_tags = [None, 0]
import csv
with open('ps03-4.csv','rb') as file:
contents = csv.reader(file)
matrix = list()
for row in contents:
matrix.append(row)
@sangheestyle
sangheestyle / coloring_my_graph.py
Created October 8, 2014 06:49
snippets for Networkx
# origin: http://stackoverflow.com/questions/24662006/python-networkx-graph-different-colored-nodes-using-two-lists
## assign a node attribute, which I am going to color according to
for node in G.nodes():
G.node[node]['category'] = my_category_dict[node]
## put together a color map, one color for a category
color_map = {'type_A':'b', 'type_B':'#FF0099', 'type_C':'#660066'}
## construct a list of colors then pass to node_color
nx.draw(G, node_color=[color_map[G.node[node]['category']] for node in G])
plt.show()