Skip to content

Instantly share code, notes, and snippets.

View tjwei's full-sized avatar

Tzerjen Wei tjwei

View GitHub Profile
import time
import sys
sys.path.append('/Users/tjw/anaconda3/envs/py35/lib/python3.5/site-packages')
from ipykernel.kernelapp import IPKernelApp
from tornado import ioloop
from bpy.app.handlers import persistent, scene_update_pre
class StepIPKernelApp(IPKernelApp):
def H2str(h):
return chr(h&0xff)+chr(h>>8)
f=open("aaa.gif", "wb")
f.write("GIF89a")
f.write("\x00\x01\x00\x01")
f.write("\xF7\x01\x00") #GCT
f.write("\xff\x00\xff")
f.write("\xff\xff\x00")
f.write("\n=1")
f.write("\r\n\x00")
import csv
dot = lambda a,b: sum(i*j for i,j in zip(a,b))
mean = lambda a: sum(a)/len(a)
rows = list(csv.DictReader(open("insurance.csv")))
data= {k: [float(i[k]) for i in rows] for k in rows[0]}
x, y = data['X'], data['Y']
n = len(x)
beta1 = (n*dot(x,y)-sum(x)*sum(y))/(n*dot(x,x)-sum(x)**2)
beta0 = mean(y)-beta1*mean(x)
print("beta0 = ",beta0,",beta1 = ",beta1)
#include <iostream>
#include <map>
#include <fstream>
int main(int argc, char **argv) {
std::map<int,unsigned char> cells;
std::ifstream is(argv[1], std::ifstream::binary);
auto loop = [&](int s, char x, char y, int cnt=0) -> bool {
while(cnt >= 0 && is.seekg(s, is.cur))
[&](int d){cnt += (d == x) - (d == y);}(is.get());
};
@tjwei
tjwei / pyconapac2014vsync
Created June 25, 2014 13:48
PyCon APAC 2014 video slides sync
This file has been truncated, but you can view the full file.
{
"metadata": {
"name": ""
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
@tjwei
tjwei / gist:5468350
Created April 26, 2013 15:58
Fake operator overload for big.Int in Go
package main
import (
"fmt"
"go/ast"
"go/parser"
"go/token"
"math/big"
"reflect"
"strings"