Skip to content

Instantly share code, notes, and snippets.

View towry's full-sized avatar
🎯
Focusing

Towry Wang towry

🎯
Focusing
View GitHub Profile
@towry
towry / myview.swift
Created April 10, 2016 07:34
custom nsview class
// put this in playground
class MyView : NSView {
override func drawRect(dirtyRect: NSRect) {
let pathRect = NSInsetRect(self.bounds, 1, 1)
let path = NSBezierPath(roundedRect: pathRect, xRadius: 10, yRadius: 10)
path.lineWidth = 4
NSColor.greenColor().setFill()
NSColor.blackColor().setStroke()
path.fill()
@towry
towry / poisson.js
Created March 8, 2016 03:16 — forked from nicolashery/poisson.js
Quick JavaScript implementation of Exponential and Geometric random number generators
/* Quick implementation of Exponential and Geometric random number generators
For example you can use it to simulate when an event is going to happen next, given its average rate:
Buses arrive every 30 minutes on average, so that's an average rate of 2 per hour.
I arrive at the bus station, I can use this to generate the next bus ETA:
randomExponential(2); // => 0.3213031016466269 hours, i.e. 19 minutes
*/
@towry
towry / zsh.md
Created March 3, 2016 14:20 — forked from tsabat/zsh.md
Getting oh-my-zsh to work in Ubuntu
var data = [61.5, 65.2, 72.3, 75.1, 85.0, 86.2, 61.0, 64.3, 72.1, 75.8, 79.9, 84.8, 63.1, 65.0, 77.0, 74.0, 88.0, 87.0, 60.4, 65.9, 79.5, 70.1, 80.4, 85.9, 90.0];
d3 .select('#chart')
.datum(data)
.call(histogramChart()
.width(700)
.height(250)
.lowerBand(55)
.upperBand(95)
.bins(7)
@towry
towry / _service.md
Created February 17, 2016 05:13 — forked from naholyr/_service.md
Sample /etc/init.d script

Sample service script for debianoids

Look at LSB init scripts for more information.

Usage

Copy to /etc/init.d:

# replace "$YOUR_SERVICE_NAME" with your service's name (whenever it's not enough obvious)
var __on = false;
var vis = (function(){
var stateKey, eventKey, keys = {
hidden: "visibilitychange",
webkitHidden: "webkitvisibilitychange",
mozHidden: "mozvisibilitychange",
msHidden: "msvisibilitychange"
};
from bs4 import BeautifulSoup
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
USE_PROXY = True
if USE_PROXY:
import requesocks as requests
else:
@towry
towry / emojid.js
Created November 12, 2015 04:40
detect emoji support
var emojiSupported = (function() {
var node = document.createElement('canvas');
if (!node.getContext || !node.getContext('2d') ||
typeof node.getContext('2d').fillText !== 'function')
return false;
var ctx = node.getContext('2d');
ctx.textBaseline = 'top';
ctx.font = '32px Arial';
ctx.fillText('\ud83d\ude03', 0, 0);
return ctx.getImageData(16, 16, 1, 1).data[0] !== 0;
@towry
towry / p4merge4git.md
Created November 4, 2015 13:58 — forked from tony4d/p4merge4git.md
Setup p4merge as a visual diff and merge tool for git
@towry
towry / what-forces-layout.md
Last active September 20, 2015 11:17 — forked from paulirish/what-forces-layout.md
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout. This is also called reflow or layout thrashing, and is common performance bottleneck.

Element

Box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
  • elem.clientLeft, elem.clientTop, elem.clientWidth, elem.clientHeight
  • elem.getClientRects(), elem.getBoundingClientRect()