Skip to content

Instantly share code, notes, and snippets.

View linstantnoodles's full-sized avatar
🎯
Focusing

Alan L. linstantnoodles

🎯
Focusing
View GitHub Profile
@linstantnoodles
linstantnoodles / ebert_amazon.py
Last active July 5, 2020 19:31
Get amazon prime information on Roger Ebert Great Movies
import requests
import csv
import os
import json
import re
from bs4 import BeautifulSoup
import mechanize
from random import choice
user_agents = ['Mozilla/5.0 (X11; U; Linux; i686; en-US; rv:1.6) Gecko Debian/1.6-7','Konqueror/3.0-rc4; (Konqueror/3.0-rc4; i686 Linux;;datecode)','Opera/9.52 (X11; Linux i686; U; en)']
random_user_agent = choice(user_agents)
@linstantnoodles
linstantnoodles / namer.ml
Last active April 24, 2017 12:15
ocaml type checker
(* Name: Alan Lin
Assignment: Problem Set 6 -> Namer
*)
module Namer =
struct
type typ = IntType | BoolType
type value = BoolValue of int | IntValue of int
type ast = Const of int * typ
| App of string * ast list
function ArrayAdditionI(arr) {
var valMap = {}; // Cache sums
arr.sort(function(a,b) { return a - b;});
var largestNum = arr.pop();
for (var i = 0; i < arr.length; i++) {
var combos = Object.keys(valMap);
for (var j = 0; j < combos.length; j++) {
var newCombo = arr[i] + (+combos[j]);
if (newCombo === largestNum) return "true";
@linstantnoodles
linstantnoodles / gist:5193227
Created March 19, 2013 02:21
hanoi recursive
function move(n, f, d, t) {
if (n > 0) {
move(n - 1, f, t, d);
d.push(f.pop());
move(n - 1, t, d, f);
}
}
public static int findElement(int[] a, int l, int r, int x){
int m = (l+r)/2;
int t = -1;
if(x == a[m]) return m;
if(l < r){
if(a[l] == a[m]){
if(x == a[l])
t = l;
public static final int STR_SIZE(int n) {
float bytesPerChar = Charset.defaultCharset().newEncoder().maxBytesPerChar();
return ((n+1) * (int)bytesPerChar); //1 xtra null char
}
public synchronized String getString(int offset) {
contents.position(offset);
String new_str = "";
while(true){
char a = contents.getChar();
if(a == '\0') break;
new_str += a;
}
return new_str;
}
let rec sublists a = match a with
[] -> [[]]
|first::rest -> let b = sublists rest in
let c = List.map (fun g -> first::g) b in
c @ b;;
(*
val sublists : 'a list -> 'a list list = <fun>
# let a = [1;2;3];;
val a : int list = [1; 2; 3]
@linstantnoodles
linstantnoodles / sublists.ml
Created December 20, 2012 19:51
generate all sublists of a list
(*let A = [1;2;3]
* genSublists A will yield
* [[1]; [1; 2]; [1; 3]; [1; 2; 3];[2]; [2; 3]; [3]; []] *)
let rec gen list head =
match list with
[] -> []
| first::rest -> let start = (head @ [first]) in
let rec append list =
match list with
@linstantnoodles
linstantnoodles / transitive.ml
Created October 12, 2012 01:20
checks a relation for transitive property
(*checks for existence of (b,c)*)
let rec exists_bc(b,r) =
match r with
[] -> false
| (x,c)::tail -> (x == b) || exists_bc(b,tail);;
(*constructs the list of relations that must exist for element a*)
let rec create_ac(a,b,r) =
match r with
[] -> []