Skip to content

Instantly share code, notes, and snippets.

View nickleefly's full-sized avatar

Xiuyu Li nickleefly

  • Shanghai
View GitHub Profile
@nickleefly
nickleefly / preg_replace.php
Created December 31, 2012 06:15
url to clickable link
<!--
a few lines of code to make a url into a clickable link
using lazy star (.*?) and $0
-->
<?php
$string = 'http://www.haha.com www.haha.com hahahaha https://www.haha.com';
$string = $string." ";
$stringall = preg_replace('/((https:\/\/)|(http:\/\/)|(www\.))(.*?)(?=\s)/i','<a href="$0" target="_blank">$0</a>',$string);
#!/bin/sh
git filter-branch --env-filter '
an="$GIT_AUTHOR_NAME"
am="$GIT_AUTHOR_EMAIL"
cn="$GIT_COMMITTER_NAME"
cm="$GIT_COMMITTER_EMAIL"
if [ "$GIT_COMMITTER_EMAIL" = "your@email.to.match" ]
@nickleefly
nickleefly / insert.js
Last active December 10, 2015 19:48
insert async
var insertElement = function(data, callback) {
var timeout = Math.ceil(Math.random() * 1000);
setTimeout(function() {
callback(null, data);
}, timeout);
};
var insertAll = function(coll, callback) {
var queue = coll.slice(0),
elem;
@nickleefly
nickleefly / sublime-windows.md
Last active December 10, 2015 23:08
sublime text shortcut windows

#Editing ##Keypress Command

  • Ctrl + X Delete line
  • Ctrl + ↩ Insert line after
  • Ctrl + ⇧ + ↩ Insert line before
  • Ctrl + ⇧ + ↑ Move line/selection up
  • Ctrl + ⇧ + ↓ Move line/selection down
  • Ctrl + L Select line - Repeat to select next lines
  • Ctrl + D Select word - Repeat select others occurrences
@nickleefly
nickleefly / sublime.mac
Last active December 10, 2015 23:09
mac sublime shortcut
h1. Sublime Text 2 - Useful Shortcuts (Mac OS X)
h2. General
| *⌘T* | go to file |
| *⌘⌃P* | go to project |
| *⌘R* | go to methods |
| *⌃G* | go to line |
| *⌘KB* | toggle side bar |
| *⌘⇧P* | command prompt |
@nickleefly
nickleefly / decode-server.js
Last active December 11, 2015 09:08
server decode
var http = require('http');
var url = require('url');
var pages = [
{id: '1', route: '', output: 'Woohoo!'},
{id: '2', route: 'about', output: 'A simple routing with Node example'},
{id: '3', route: 'another page', output: function() {return 'Here\'s '+this.route;}}
];
http.createServer(function (request, response) {
@nickleefly
nickleefly / readWriteFile.js
Created January 20, 2013 09:18
read from input, write to output create dir then remove it
var fs = require('fs');
var file = fs.createReadStream('./input.txt', {flags: 'r'} );
var out = fs.createWriteStream('./output.txt', {flags: 'w'});
file.pipe(out);
var fs = require('fs');
fs.mkdir('./newdir', 0666, function(err) {
if(err) throw err;
@nickleefly
nickleefly / copyImage.js
Created January 20, 2013 09:28
copy an image
var fs = require('fs');
var readStream = fs.createReadStream('./cat.jpg');
var writeStream = fs.createWriteStream('./cat_copy.jpg');
readStream.on('data', function(data) {
writeStream.write(data);
});
readStream.once('end', function() {
@nickleefly
nickleefly / static.js
Created January 22, 2013 11:34
server static file
var http = require('http');
var path = require('path');
var fs = require('fs');
http.createServer(function(request, response) {
var lookup = path.basename(decodeURL(request.url)) || 'index.html';
f = 'content/' + lookup;
fs.exists(f, function(exists) {
if(exists) {
fs.readFile(f, function(err, data) {
@nickleefly
nickleefly / fs_read_stream.js
Last active December 11, 2015 11:38
createReadStream
var fs = require('fs');
var readStream = fs.createReadStream('/Users/asus/Documents/work/script.js');
readStream.pause();
readStream.on('data', function(data) {
console.log('got some data:', data);
readStream.pause();