Skip to content

Instantly share code, notes, and snippets.

@HakurouKen
HakurouKen / Sieve of Eratosthenes.js
Created October 17, 2014 03:50
Sieve of Eratosthenes Javascript version
var sieve = function(num) {
var arr = [],
primes = [],
i = 0,
curPrime;
num = parseInt(num);
if (isNaN(num) || num < 2) {
return primes;
}
@HakurouKen
HakurouKen / Zepto.lazyload.js
Last active August 29, 2015 14:11
A simple lazyload plugin for Zepto/jQuery
(function($){
$.fn.lazyload = function(options){
var $container = options.$container,
$window = $(window),
elems = [];
options = $.extend({
attr: 'data-lazyload',
$container: $window,
advance: 100,
@HakurouKen
HakurouKen / config.ini
Last active August 29, 2015 14:14
A simple python shell to send email (SMTP)
[global]
email = [email protected]
password = your_email_password
host = smtp.your_email_host.com
@HakurouKen
HakurouKen / req.js
Created March 17, 2015 15:35
A basic lib to process client request for Node.js
var http = require('http'),
https = require('https'),
iconv = require('iconv-lite'),
url = require('url'),
querystring = require('querystring'),
fs = require('fs');
var request = module.exports = {};
function parseUrl(urlStr){
@HakurouKen
HakurouKen / brainfuck.js
Created April 2, 2015 03:38
A simple BrainFuck Javascript interpreter
var BrainFuck = (function(){
function getBracketsPair(code){
var stack = [],
bracket = [],
start,
i,l;
for (i = 0, l = code.length; i < l; i++ ) {
if (code[i] === '[') {
stack.push(i);
@HakurouKen
HakurouKen / bilibili-search.xml
Created April 5, 2015 13:22
Firefox search tool for bilibili.
<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"
xmlns:moz="http://www.mozilla.org/2006/browser/search/">
<ShortName>Bilibili-Search</ShortName>
<Description>Search in Bilibili</Description>
<InputEncoding>UTF-8</InputEncoding>
<Image width="16" height="16">http://www.bilibili.com/favicon.ico</Image>
<Url type="text/html" method="GET" template="http://www.bilibili.com/search?keyword={searchTerms}">
</Url>
<moz:SearchForm>http://www.bilibili.com/</moz:SearchForm>
@HakurouKen
HakurouKen / git-paste.js
Last active August 29, 2015 14:19
A greasemonkey plugin to copy github && gist code quickly.
// ==UserScript==
// @name GitPaste
// @name:zh-CN GitPaste
// @author Hakurouken
// @description copy github && gist code quickly
// @description:zh-cn 快速的复制 github 和 gist 的代码
// @namespace GitPaste/Hakurouken
// @icon https://github.com/favicon.ico
// @encoding utf-8
// @date 12/04/2015
@HakurouKen
HakurouKen / jQuery.template.js
Created April 24, 2015 08:00
A jQuery/Zepto template plugin based on MicroTemplate.
(function($) {
var cache = {};
var partial = function(str) {
return str.replace(/<%\+(.*)%>/, function(child, name) {
name = name.trim();
return !/[^\w-_]/.test(name) ? document.getElementById(name).innerHTML : name;
});
};
@HakurouKen
HakurouKen / cache.js
Created May 11, 2015 07:05
A storage wrapper based on localStorage.
var Cache = (function(global){
var Cache = {};
var storage = global.localStorage;
Cache.isSupport = (function(){
return !!storage;
})();
Cache.set = function(key,val){
@HakurouKen
HakurouKen / strHash.js
Created June 2, 2015 02:10
javascript string hash
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define([], factory);
} else if (typeof exports === 'object') {
module.exports = factory();
} else {
root['strHash'] = factory();
}
}(this, function () {
var strHash = {