Skip to content

Instantly share code, notes, and snippets.

View fundon's full-sized avatar
🎯
Focusing

Fangdun Tsai fundon

🎯
Focusing
View GitHub Profile
@fundon
fundon / utf8length.js
Created May 21, 2012 14:39 — forked from vmi/utf8length.js
Calulate byte length of string as UTF-8.
/*
* Fair License (Fair)
*
* Copyright (c) 2012, IWAMURO Motonori
*
* Usage of the works is permitted provided that this instrument is
* retained with the works, so that any entity that uses the works is
* notified of this instrument.
*
* DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY.
@fundon
fundon / arcfour.js
Created May 21, 2012 14:39 — forked from bellbind/arcfour.js
[javascript]arcfour aka RC4 enc/decript function
// arcfour aka RC4 enc/decrypt function
// see: http://en.wikipedia.org/wiki/RC4
arcfour = (function () {
"use strict";
var swap = function (a, i, j) {
var tmp = a[i];
a[i] = a[j];
a[j] = tmp;
};
@fundon
fundon / consumer_producer.clj
Created May 18, 2012 07:51
Queue based consumer/producer.
;; This example shows how to create a single producer and multiple consumers.
;; Each consumer will receive the message. I'm not sure if internally it's handled in a round-robin manner,
;; but when queue does not listen for messages (e.q. it's processing them), it won't receive one.
;;
;; In order to run it, use:
;;
;; lein2 run --mode consumer
;;
;; And in other window:
;;
@fundon
fundon / LICENSE.txt
Created May 18, 2012 07:49 — forked from yaoduren123/LICENSE.txt
convert RGB to HEX
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Jed Schmidt <http://jed.is>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@fundon
fundon / textColor.js
Created May 17, 2012 06:10 — forked from swvitaliy/textColor.js
textColor
;(function(ns)
{
var color = {};
color.reHexTest = /^\s*#[\da-fA-F]{1,6}\s*$/;
color.reRgbTest = /^\s*rgb\s*\(\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}\s*\)\s*$/i;
color.reRgbExec = /^\s*rgb\s*\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)\s*$/i;
color.reHexExec = /^\s*#([\da-fA-F]{1,2})([\da-fA-F]{1,2})?([\da-fA-F]{1,2})?\s*$/;
@fundon
fundon / LICENSE.txt
Created May 12, 2012 03:23
base64 decoder
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright* (C) 2011 Alex Kloss <[email protected]>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@fundon
fundon / nextTick.js
Created April 17, 2012 19:07 — forked from mmalecki/nextTick.js
process.nextTick vs setTimeout(fn, 0)
for (var i = 0; i < 1024 * 1024; i++) {
process.nextTick(function () { Math.sqrt(i) } )
}
@fundon
fundon / python-vs-go.mdown
Created April 16, 2012 07:47 — forked from sma/python-vs-go.mdown
Ich versuche Go zu lernen, indem ich das Grundgerüst für einen Python-Interpreter schreibe

Python vs. Go

Bekanntlich kann CPython Code nicht parallel in Betriebssystem-Threads ausführen. Es gibt den Global Interpreter Lock (GIL), der verhindert, dass dies passiert. Auf einem Computer mit mehr als einer CPU (dem Standard heutzutage), kämpfen alle paar Millisekunden die CPUs um den GIL, was dazu führt, dass die Laufzeit von CPython in diesem Fall deutlich schlechter als das theoretische Maximum ist.

Dieses Python-Programm braucht auf meinem Rechner etwa 9,5s:

def count_down(n):
    while n > 0:

n -= 1

@fundon
fundon / iir-retina.css
Created April 16, 2012 07:47 — forked from aarongustafson/iir-retina.css
Code examples for iIR Redux
@media only screen and (-moz-min-device-pixel-ratio: 2),
only screen and (-ms-min-device-pixel-ratio: 2),
only screen and (-o-min-device-pixel-ratio: 2),
only screen and (-webkit-min-device-pixel-ratio: 2),
only screen and (min-device-pixel-ratio: 2)
{
#social-links img {
background: top left no-repeat;
background-size: 25px 25px;
display: inline-block;