Skip to content

Instantly share code, notes, and snippets.

@killwing
killwing / hackertyper.js
Created June 9, 2011 06:48
[hackertyper] type codes in your shell...
var util = require('util');
var fs = require('fs');
var type = function(data, completer) {
var lines = data.split(' ');
var i = 0;
var timer = setInterval(function() {
var s = lines[i++];
while (lines[i] == '') {
@killwing
killwing / flickrshortener.html
Created June 9, 2011 08:54
[flickrshortener] make flickr link short
<html>
<head>
<script type="text/javascript">
function shorten() {
var s = document.getElementById("url").value.match(/^https?:\/\/[^/]*\bflickr\.com\/(photos\/[^/]+\/(\d+))/i);
if (s && s.length && s[2]) {
var num = s[2];
if (typeof num !== 'number') {
num=parseInt(num);
}
@killwing
killwing / algorithm.js
Created June 30, 2011 02:52
[algorithm] various algorithm samples
#!/usr/local/bin/node
var assert = require('assert');
// utils
Array.prototype.swap = function(a, b) {
if (a == b) {
return;
}
var tmp = this[a];
@killwing
killwing / mdcontentgen.js
Created December 29, 2011 11:24
[mdcontentgen] generate content list for markdown
#!/usr/local/bin/node
var fs = require('fs');
var file = process.argv[2];
if (!file) throw 'no input file';
var seq = false;
if (file == '-s') {
if (!process.argv[3]) throw 'no input file';
@killwing
killwing / seqgen.cfg
Created March 15, 2012 07:04
[seqgen] generate ascii sequence
Alice|Bob|Carol
1|1->2|INVITE(hello)
2|2->3|INVITE
-|3|waiting...
3|2<-3|200OK
4|1<-2|200OK
@killwing
killwing / markdown.css
Created June 15, 2012 17:55
[markdowncss]flavored markdown style
/*
CSS stylesheet is based on Kevin Burke's Markdown.css project:
http://kevinburke.bitbucket.org/markdowncss
For code highlighting:
<link rel="stylesheet" href="http://yandex.st/highlightjs/6.1/styles/magula.min.css">
<script src="http://yandex.st/highlightjs/6.1/highlight.js"></script>
<script src="http://yandex.st/highlightjs/6.1/languages/cpp.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
*/
@killwing
killwing / tw2md.js
Created September 22, 2012 10:25
[tw2md] convert tiddler of tiddlywiki to strapdownjs
#!/usr/local/bin/node
var fs = require('fs');
Function.prototype.mlstr = function() {
var lines = new String(this);
return lines.substring(lines.indexOf("/*") + 2, lines.lastIndexOf("*/"));
};
String.prototype.dup = function(n) {
var sb = '';
@killwing
killwing / convertArgsStrToArray.sh
Created November 7, 2012 17:44
[convertArgsStrToArray] convert args str to array
#!/bin/bash
returnVal=()
convertArgsStrToArray() {
local concat=""
local t=""
returnVal=()
for word in $@; do
local len=`expr "$word" : '.*"'`
@killwing
killwing / Registry.js
Created November 19, 2012 08:00
[Registry] a simple registry without moving elements
#!/usr/local/bin/node
var Registry = function() {
this.r = [null];
};
Registry.prototype.register = function(object) {
var id = this.r[0];
if (id === null) {
this.r.push(object);
@killwing
killwing / escapeXml.cpp
Created November 20, 2012 07:48
[escapeXml] escape XML special chars
#include <iostream>
#include <string>
using namespace std;
std::string escapeXml(const std::string& s) {
std::string ret;
std::string::size_type i = 0;
std::string::size_type pos = 0;
for (; i != s.size(); ++i) {
std::string rep;