Skip to content

Instantly share code, notes, and snippets.

@rachtsingh
rachtsingh / fbharvard.js
Last active January 1, 2016 17:29
script to parse Facebook page for Harvard Class of 2018 and extract the '20 facts' information and dump it to a JSON file. To use, set up a JavaScript Facebook app and launch these scripts after authentication
function executeScript(){
re = new RegExp("[4][\:|\.|\)|\-][^1-9]"); // yeaaaaaah REGEXs (also the 4 is there because of that 2 truths and a lie thing)
function findmatches(response){
console.log("parsing page"); // just for kicks
flag = true;
if (response.data.length < 2){ // empty response, sort of
flag = false;
}
if(flag){
response.data.forEach(function(post){
@rachtsingh
rachtsingh / mergesort.cpp
Last active January 3, 2016 00:09
issues
int acc[NMAX];
void merge(int low, int mid, int high){
// one block from [low --> mid] and one from [mid + 1 --> high]
// sizes (mid - low + 1), and (high - mid)
// this one actually changes their places on the original array
vector<long long> lower(acc + low, acc + mid + 1);
vector<long long> higher(acc + mid + 1, acc + high + 1);
@rachtsingh
rachtsingh / I.5
Last active January 3, 2016 00:09
weird issues with USACO median
1000 47506
70920
34639
63807
71201
40169
85943
98395
24541
46944
@rachtsingh
rachtsingh / queue.py
Last active January 3, 2016 02:28
kind of a queue for Moritz
class Queue():
def __init__(self):
self.elementarray = [0] * 25 # initialize to 25 0s for now (basically) empty
self.head = 0
self.tail = 0
def push(self, element):
self.elementarray[self.tail] = element # basically set the tail'th element to be 'element'
self.tail += 1 # shift the tail number
@rachtsingh
rachtsingh / download.js
Created January 26, 2014 20:26
A script to download the 20 facts information about the Harvard Class of 2018 and encrypt the resulting JSON. Obviously some information deleted for privacy
function executeScript(){
var no = {}; // list of excluded users
re = new RegExp("[4][\:|\.|\)|\-][^1-9]");
function findmatches(response){
flag = true;
if (response.data.length < 2){ // empty response, sort of
flag = false;
}
if(flag){
response.data.forEach(function(post){
class vector(list):
pass
def wrap(attr):
def wrapped(a, b):
return vector(map(lambda x, y: getattr(x, attr)(y), a, b))
return wrapped
for attr in "__add__ __sub__ __mul__ __div__".split():
setattr(vector, attr, wrap(attr))
@rachtsingh
rachtsingh / wordinfo.py
Created March 23, 2015 00:43
Scraper for WordInfo
import scrapy
class WordUnit(scrapy.Item):
# define the fields for your item here like:
# name = scrapy.Field()
name = scrapy.Field()
link = scrapy.Field()
small_desc = scrapy.Field()
desc = scrapy.Field()
words = scrapy.Field()
@rachtsingh
rachtsingh / forgrace.js
Created May 26, 2015 18:14
Basic structure
angular.module('index.controllers', [])
.controller('Ctrl', ['$scope', '$http', 'Service', function($scope, $http, Service){
}]);
angular.module('index.services')
.factory('Service', [function(){
var Service = {
stuff: 'here'
};
@rachtsingh
rachtsingh / process.py
Created October 13, 2015 01:20
Preprocessing of Pos/Neg review data
import h5py
import numpy as np
import random
import re
import pickle
import pdb
from sklearn.utils import resample
# from process_data.py
def clean_str(string, TREC=False):
@rachtsingh
rachtsingh / main.c
Created December 30, 2016 01:09
explanation of passing by value
#include <stdio.h>
void swap_values_1(int p, int q) {
printf("where are the local variables in this function allocated? p: %p, q: %p\n", &p, &q);
int tmp = q;
q = p;
p = tmp;
}
void swap_values_2(int *m, int *n) {