Skip to content

Instantly share code, notes, and snippets.

View yuchen's full-sized avatar
🌴
On vacation

clark yuchen

🌴
On vacation
  • china, shanghai
  • 12:08 (UTC +08:00)
View GitHub Profile
// Load the TCP Library
net = require('net');
// Keep track of the chat clients
var clients = [];
// Start a TCP Server
net.createServer(function (socket) {
// Identify this client
// (A)scii(B)inary(C)onverter
// (c) 2013 Stephan Schmitz <eyecatchup@gmail.com>
var ABC = {
toAscii: function(bin) {
return bin.replace(/\s*[01]{8}\s*/g, function(bin) {
return String.fromCharCode(parseInt(bin, 2))
})
},
toBinary: function(str, spaceSeparatedOctets) {
return str.replace(/[\s\S]/g, function(str) {
@yuchen
yuchen / struct-example1.php
Last active August 29, 2015 14:05 — forked from branneman/Struct.php
PHP Struct class
<?php
require 'Struct.php';
// define a 'coordinates' struct with 3 properties
$coords = Struct::factory('degree', 'minute', 'second' ,'pole');
// create 2 latitude/longitude numbers
$lat = $coords->create(35, 41, 5.4816, 'N');
$lng = $coords->create(139, 45, 56.6958, 'E');
@yuchen
yuchen / microtime-explode.php
Last active August 29, 2015 14:05 — forked from branneman/gist:951833
Timing script execution at high-precision
<?php
$time1 = explode(' ', microtime());
$time1 = $time1[1] . substr($time1[0], 1, -2);
// your code
$time2 = explode(' ', microtime());
$time2 = $time2[1] . substr($time2[0], 1, -2);
@echo off
@echo This batchfile changes your password 30 times into a temporary password, and finally into your given password.
@echo This way, you can use your 'old' password, when you are forced to change it ;)
SET /P user=username:
SET /P pwd=password:
echo username: %user%
net user %user% C6us4deSAf /domain
//
// asyncParallel(tasks, [callback])
//
// Run an array of functions in parallel, without waiting until the previous
// function has completed. Once the tasks have completed, final callback is called.
//
// Source:
// https://gist.github.com/branneman/4541190
// Inspired by:
// https://github.com/caolan/async#parallel
@yuchen
yuchen / server.js
Created August 20, 2014 01:08 — forked from branneman/server.js
var fs = require('fs'),
exec = require('child_process').exec,
express = require('express'),
app = express();
app.get('/static/img/*.svg.*.png', function(req, res) {
var pngFile = 'src' + req.url,
svgFile = pngFile.substring(0, pngFile.indexOf('.svg') + 4);
if (!fs.existsSync(svgFile)) {
return res.render('404', {
@yuchen
yuchen / event.js
Created August 20, 2014 01:08 — forked from branneman/event.js
$(function() {
var resizeEnd;
$(window).on('resize', function() {
clearTimeout(resizeEnd);
resizeEnd = setTimeout(function() {
$(window).trigger('resizeEnd');
@yuchen
yuchen / dump.php
Created August 20, 2014 01:08 — forked from branneman/dump.php
function dump($var) {
ob_start();
var_dump($var);
$output = ob_get_clean();
echo preg_replace("/=>(\s+)/m", ' => ', $output);
}
/**
* Strict mode
* Opt in to a restricted variant of JavaScript.
*/
'use strict';
(function() { 'use strict'; });
/**
* Array.prototype.forEach()
* Executes a provided function once per array element.