Skip to content

Instantly share code, notes, and snippets.

View jsyang's full-sized avatar
🎱
Magic numbers

Jim Yang jsyang

🎱
Magic numbers
View GitHub Profile
@jsyang
jsyang / gist:1029479
Created June 16, 2011 15:24
ReddyFeeeeeerZeerah
/*
jsyang's solutions for ReadyForZero challenge.
June 16, 2011
*/
/*\
|*| Loading question 1...
|*|
|*| The 3072 characters below contain a sequence of 5 characters which is
|*| repeated. However, there is a twist: one of the sequences has a typo.
@jsyang
jsyang / TellerTranscript
Created July 11, 2011 00:58
Teller talks!
Transcript of http://www.youtube.com/watch?v=J5x14AwElOk
jsyang ~ 7:19 PM 7/10/2011
Teller is part of the Penn and Teller duo that's playing at the Rio right now,
which is quite excellent. And he has 32 years in magic that he's going to
summarize in just a few minutes.
[Teller speaks]
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Swarming - jsFiddle demo by g105b</title>
<script type='text/javascript' src='http://code.jquery.com/jquery-1.4.4.min.js'></script>
<link rel="stylesheet" type="text/css" href="/css/normalize.css">
<link rel="stylesheet" type="text/css" href="/css/result-light.css">
@jsyang
jsyang / ca.py
Created October 20, 2011 18:57
crown and anchor heuristics
'''
Crown and Anchor (spinning wheel version)
Photo of the wheel: http://www.jackofallspades.ca/wheel-rentals.php
symbols = [ "diamonds", "clubs", "hearts", "spade", "crowns", "anchors" ]
We'll use the indices to refer to the suit.
Players bet ($0.50 to $2.00) on a symbol. Once all bets are placed, spinner is spun.
Banker pays out the bet to the player who bet on a symbol that appeared on the wheel.
@jsyang
jsyang / quixey.py
Created October 25, 2011 19:42
quixey.py
'''
1. Write a (stateless) function nextPermutation that takes a permutation (as a
list) on the elements of the set {1, ..., n} and returns the "next" permutation,
so that chaining n! calls to nextPermutation([1, ..., n]) results in the generation
of every permutation on the set {1, ..., n}.
'''
def nextPermutation(l):
# select subset of l to use as digits of next
for i in range(len(l)-2,-1,-1):
@jsyang
jsyang / app.js
Created June 18, 2013 06:49 — forked from elranu/app.js
//app.js Socket IO Test
var app = require('express').createServer(),
redis = require('socket.io/node_modules/redis'),
io = require('socket.io').listen(app);
var pub = redis.createClient(port, "url");
var sub = redis.createClient(port, "url");
var store = redis.createClient(port, "url");
pub.auth('pass', function(){console.log("adentro! pub")});
sub.auth('pass', function(){console.log("adentro! sub")});
@jsyang
jsyang / gist:8034960
Created December 19, 2013 05:50
.bash_profile
alias d='ditz'
alias coffee='/usr/local/share/npm/bin/coffee'
alias cwc='coffee -b -w -c'
alias cwp='coffee -b -w -p'
alias cw='cwc --output core/ coffeecore/'
alias ip='curl ipecho.net/plain ; echo'

To run this, you can try:

curl -ks https://gist.github.com/nicerobot/2697848/raw/uninstall-node.sh | bash

I haven't tested this script doing it this way but i run a lot of my Gists like this so maybe this one'll work too.

Alternatively,

curl -ksO https://gist.github.com/nicerobot/2697848/raw/uninstall-node.sh

chmod +x ./uninstall-node.sh

/**
* References:
* [1] ftp://ftp.idsoftware.com/idstuff/source/quake3-1.32b-source.zip
* [2] http://www.lomont.org/Math/Papers/2003/InvSqrt.pdf
* [3] http://en.wikipedia.org/wiki/Newton%27s_method
* [4] https://developer.mozilla.org/en/JavaScript_typed_arrays
* [5] http://en.wikipedia.org/wiki/Fast_inverse_square_root
*/
const QUAKEx32 = 0x5f3759df
@jsyang
jsyang / Bot as a bookmarklet
Last active August 29, 2015 14:05
ColorRunPlBot.js
javascript:(function(b){function a(d){return d.style.backgroundColor.match(/[\d]+/g).reduce(function(g,f){return g- -f},0)}function c(j){var l=document.querySelector("#color-1");var h=document.querySelector("#color-2");var f=a.bind(null,l);var g=a.bind(null,h);var k=new MouseEvent("click",{view:window});this.react=function(){if(f()>g()){if(this.shouldQuit){h.dispatchEvent(k)}else{l.dispatchEvent(k)}}else{if(this.shouldQuit){l.dispatchEvent(k)}else{h.dispatchEvent(k)}}};this.shouldQuit=false;var d=new MutationObserver(function(e){if(j>0){this.onStyleMutation(e[0]);j--}else{this.stopGame(e[0])}}.bind(this));d.observe(l,{attributes:true});this.injectStyle(".color { opacity: 0.1 };");this.stopGame=function(i){this.shouldQuit=true;d.disconnect();this.injectStyle(".color { opacity: 1 };");this.onStyleMutation(i)}.bind(this)}c.prototype.injectStyle=function(f){var d=document.createElement("style");d.textContent=f;document.body.appendChild(d)};c.prototype.onStyleMutation=function(d){if(d.attributeName==="style"){wind