Skip to content

Instantly share code, notes, and snippets.

View longouyang's full-sized avatar

Long Ouyang longouyang

View GitHub Profile
@longouyang
longouyang / main.js
Last active May 6, 2022 02:27
octokit-test
import { octokit } from './index.js';
import fs from 'fs';
// if no data.json file in root, make a new one
if (!fs.existsSync('./data.json')) {
let data = [{ query: 'defi language:javascript stars:>1000', extensions: ['js', 'ts', 'sol', 'yml'], currentPage: 0, endPage: 10, lastRunDate: null, files: [] }]
fs.writeFileSync('./data.json', JSON.stringify(data));
}
async function searchRepo(query, page) {
@longouyang
longouyang / simple_cb.py
Last active November 27, 2023 15:13 — forked from DavidYKay/simple_cb.py
Simple color balance algorithm
# Simple color balance algorithm using Python 2.7.8 and OpenCV 2.4.10.
# Ported from: http://www.morethantechnical.com/2015/01/14/simplest-color-balance-with-opencv-wcode/
# See also http://web.stanford.edu/~sujason/ColorBalancing/simplestcb.html
import cv2
import math
import numpy as np
import sys
def apply_mask(matrix, mask, fill_value):
@longouyang
longouyang / gradient-ascent.js
Created May 22, 2017 22:55
gradient ascent in webppl
var f = function(theta) {
//return 30 * Math.log(theta) + 20 * Math.log(1-theta)
return Binomial({p: theta, n: 30}).score(14)
}
globalStore["x"] = 0.001;
repeat(100,
function() {
var x = globalStore["x"],
@longouyang
longouyang / random-subsets.js
Created April 25, 2017 23:39
Uniformly sampling random subsets in webppl
// uses lodash, not underscore
var sampleSubset = function(xs) {
var n = xs.length;
var toBinary = function(dec){
// convert decimal to binary
var _s = (dec >>> 0).toString(2);
// do left padding
var k = _s.length;
var n = 15000;
// Switching from repeat to map(fn, _.range(n)) causes this to use lots of
// memory. (~1GB)
// Setting n = 20000 gives "Allocation failed - process out of memory". Up the
// limit with e.g. node --max-old-space-size=2000
var data = repeat(n, function(i) {
var obj = {
@longouyang
longouyang / Measurements-counties.csv
Created June 12, 2015 14:56
Minnesota data from radon examples in Gelman + Hill
We can make this file beautiful and searchable if this error is corrected: Unclosed quoted field in line 9.
"county","idnum","state","state2","stfips","zip","region","typebldg","floor","room","basement","windoor","rep","stratum","wave","starttm","stoptm","startdt","stopdt","activity","pcterr","adjwt","dupflag","zipflag","cntyfips","Uppm"
"AITKIN",5081,"MN","MN",27,55735,5,1,1,3,"N",NA,2,4,41,930,930,12088,12288,2.2,9.7,1146.49919,1,0,1,0.502054
"AITKIN",5082,"MN","MN",27,55748,5,1,0,4,"Y",NA,5,2,40,1615,1615,11888,12088,2.2,14.5,471.366223,0,0,1,0.502054
"AITKIN",5083,"MN","MN",27,55748,5,1,0,4,"Y",NA,3,2,42,1030,1515,20288,21188,2.9,9.6,433.316718,0,0,1,0.502054
"AITKIN",5084,"MN","MN",27,56469,5,1,0,4,"Y",NA,2,2,24,1410,1410,122987,123187,1,24.3,461.62367,0,0,1,0.502054
"ANOKA",5085,"MN","MN",27,55011,3,1,0,4,"Y",NA,3,2,40,600,600,12888,13088,3.1,13.8,433.316718,0,0,3,0.428565
"ANOKA",5086,"MN","MN",27,55014,3,1,0,4,"Y",NA,5,2,22,900,1300,120287,121187,2.5,12.8,471.366223,0,0,3,0.428565
"ANOKA",5087,"MN","MN",27,55014,3,1,0,4,"Y",NA,5,2,28,2000,2025,121887,122087,1.5,14.5,471.366223,0,0,3,0.428565
"ANOKA",5088,"M
@longouyang
longouyang / gist:d2963f3d095e3b79a3f8
Created September 4, 2014 00:01
retrospective mcmc crp
var rDPmem = $b({
name: 'rDPmem',
desc: 'Retrospective implementation of DPmem',
params: [{name: 'alpha', type: 'positive real', desc: 'Concentration parameter'},
{name: 'f', type: 'function', desc: 'Function to stochastically memoize'}],
fn: function(alpha, f) {
var allStickSets = {};
var cumulativeStickSums = {};
var caches = {};
@longouyang
longouyang / gist:8815976
Created February 5, 2014 01:37
Big Scheme command
(length (list 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
@longouyang
longouyang / gist:6369737
Created August 28, 2013 18:47
emacs regexp to capitalize heads of sentences
\\(^\\|\\. \\)\\([a-z]\\)
\1\,(upcase \2)
@longouyang
longouyang / gist:3688502
Last active April 23, 2022 20:22
Random combinations in Church (Buckles-Lybanon '77)
(define (pn x) (for-each display (list x "\n")))
(define (! n)
(let iter ((product 1)
(counter 1))
(if (> counter n)
product
(iter (* counter product)
(+ counter 1)))))