Skip to content

Instantly share code, notes, and snippets.

View leegao's full-sized avatar

Lee Gao leegao

  • Google
  • Jersey City, NJ
View GitHub Profile
'BLD18qQhOwEylkVki91hjILTcIwbEMhUHamjkAzgyIWnl1tqOZvO+7AvOTqn036uyHAQVVbSH3/BzYMjNHTMXvogJBWI1siiMZF2zFzD0GEpuGdF+WbSIrug4fzHojQ/AAaBx2HT/tZ8hP+ITRc8z9a7ecsrGX+EBq+b3mada6zeJPxE2j47psb/J4Xnx0AEfh+lEb2GLpczI7e3o0BGP9GlmQYPSXINq87N2D8G175+cBwbMmzdfsIxr9hNGJgLGTFe/NdMP6NoAERNJOij9vzbgwiaOpdvmqBkV2HLp//Pj28HgIc392BrzFQ/slGN0/TqxugL1UY9GMpmI+GQVDSMzswGVWZ5VMjs4sSvkAmQ/p5AnrRyDoszxO+SKI5HV+OwHS0G7NcKXUMCx32xk6mVNxcpl0DwivGhJuvk/gphiG0b2f0gciQaaDJzuOJASND397ryTg4EuRYRw8D2A1lNF5lGEkzxMCGi56t4zCLduBcROWbbjBKKZer6enhbgsEytVBmzo4ONfQ+ZFv3sLhaEb72lnMkVKDD3tw7hzAoL86ObHGLOEGMUY3n9wihn1peBNBTcL3kSfH4/t9KF4qZ3GtXA++WO1h5/0edqVhDygXMUzQ87EZvcGuqLMk6iR08pFBO529aAADg8o9hHKfspYvwghDW/5HtJGL7CrGpE4Sr8FnvNvv7J3AGa9csWrhMB00P/dupnCafDuJAeCgFL0l'
@leegao
leegao / qsqrt.c
Last active August 29, 2015 13:56
See http://www.phailed.me/2012/08/somewhat-fast-square-root/ for the full derivation, including the error compensation trick, except I later discovered 3/7 worked better than 2/5
/*
* qsqrt.c
*
* Created on: Jun 6, 2012
* Author: Lee
*/
#include <stdio.h>
#include <math.h>
@leegao
leegao / graphviz.c
Last active December 30, 2015 20:09
graphviz generator
#include <stdio.h>
#include "minifile.h"
#include "minifile_private.h"
#include "minithread.h"
#include "miniheader.h"
/*
node [shape = record,height=.1];
nodei - ith block
\documentclass[11pt,a4paper]{article}
%\usepackage{fullpage}
\usepackage[total={6.5in,8.75in},
top=1.2in, left=0.9in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{amsmath, amsthm}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
#include <errno.h>
#include <limits.h>
#include <string.h>
#include <assert.h>
#include "malloc.h"
#include "memreq.h"
#define pagesize 4096
} catch (Exception e) {
- BLog.v(TAG, "GraphQL query error", e);
+ BLog.e(TAG, "GraphQL query error", e);
future.setException(e);
}
strokes = [[{"x":-32.4694,"y":-406.755},{"x":-32.9773,"y":-407.843},{"x":-33.1274,"y":-407.418},{"x":-33.5528,"y":-407.581},{"x":-33.6725,"y":-407.17},{"x":-33.8397,"y":-407.113},{"x":-33.9804,"y":-406.489},{"x":-34.1866,"y":-407.21},{"x":-34.0972,"y":-407.312},{"x":-34.0474,"y":-407.721},{"x":-33.8168,"y":-407.145},{"x":-33.1972,"y":-406.62},{"x":-32.8828,"y":-406.527},{"x":-31.9908,"y":-406.77},{"x":-31.4901,"y":-407.448},{"x":-30.7288,"y":-406.993},{"x":-29.2088,"y":-407.759},{"x":-28.2585,"y":-407.28},{"x":-27.299,"y":-407.37},{"x":-25.2517,"y":-406.916},{"x":-24.1386,"y":-406.48},{"x":-21.6648,"y":-405.788},{"x":-20.1932,"y":-405.216},{"x":-17.2013,"y":-404.229},{"x":-15.7143,"y":-404.111},{"x":-14.1496,"y":-403.6},{"x":-10.6952,"y":-403.546},{"x":-8.73107,"y":-403.586},{"x":-6.69075,"y":-403.717},{"x":-2.68588,"y":-403.726},{"x":-0.628983,"y":-403.617},{"x":3.20582,"y":-404.448},{"x":5.10758,"y":-404.798},{"x":6.94965,"y":-405.439},{"x":10.6059,"y":-406.267},{"x":12.2418,"y":-406.574},{"x":15.4362,"y":-
sendStrokes();
// find bounding box on strokes
var minx = strokes[0][0].x, miny = strokes[0][0].y, maxx = strokes[0][1].x, maxy = strokes[0][1].y;
for (var i = 0; i < strokes.length; i++) {
var stroke = strokes[i];
for (var j = 0; j < stroke.length; j++) {
var x = stroke[j].x;
var y = stroke[j].y;
if (x < minx) {
minx = x;
import urllib
import urllib2
import json
headers = {
'Host': 'webdemo.visionobjects.com',
'Connection': 'keep-alive',
'Accept': 'equation/json',
'Origin': 'http://webdemo.visionobjects.com',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36',
Can you explain why the following occurs in Python? (The culprit is roundoff, but why does it seem like 1.1 is not affected but 1.2 is?)
>>> (1.1 + 1) - 1
1.1
>>> (1.2 + 1) - 1
1.2000000000000002
>>> 1.2 + (1 - 1)
1.2
Try the same with 1.3 and 1.4