Skip to content

Instantly share code, notes, and snippets.

View bigsan's full-sized avatar

San Chen bigsan

  • LearningTech
  • Taiwan
View GitHub Profile
@bigsan
bigsan / DecodeQuotedPrintable.cs
Created July 30, 2014 07:06
CS: Decode quoted printable text with specific encoding
String DecodeQuotedPrintable(String input, Encoding encoding = null)
{
encoding = encoding ?? Encoding.UTF8;
var decoded = Regex.Replace(input, @"=([0-9a-fA-F]{2})|=\r\n",
m => m.Groups[1].Success
? Convert.ToChar(Convert.ToInt32(m.Groups[1].Value, 16)).ToString()
: "");
var rawBytes = decoded.Select(Convert.ToByte).ToArray();
@bigsan
bigsan / .zshrc
Created June 22, 2015 05:55
.zshrc using zgen
# load zgen
source "${HOME}/.zgen/zgen/zgen.zsh"
ZSHRC="${HOME}/.zshrc"
# if this file is newer than init file
if ! zgen saved || [ "${ZSHRC}" -nt "${ZGEN_INIT}" ] ; then
echo "Creating a zgen save"
zgen oh-my-zsh
@bigsan
bigsan / CleanlyMigrateFromSvn.sh
Created January 17, 2010 08:00
Git: migrate from svn to git
# source: http://www.jonmaddox.com/2008/03/05/cleanly-migrate-your-subversion-repository-to-a-git-repository/
mkdir my_blog_tmp
cd my_blog_tmp
# --no-metadata, tells GIT to leave all the SVN details behind (not the commit log)
git-svn init http://code.yoursite.net/my_blog/trunk/ --no-metadata
# remap all the SVN users to GIT users when it sucks down the source and history
git config svn.authorsfile ~/Desktop/users.txt
@bigsan
bigsan / jquery.tree.datastores.asmx.js
Created January 26, 2010 16:48
JavaScript: add asmx support to jstree 0.99
(functioin($) {
$.extend($.tree.datastores, {
"asmx": function() {
// borrow datastore from "json"
var asmxds = $.tree.datastores.json();
// override "load" function:
// 1. serialize input data into string through JSON.stringify
// 2. add "contentType" attribute to $.ajax call
asmxds.load = function(data, tree, opts, callback) {
@bigsan
bigsan / HTML5 Offline Data.js
Created October 27, 2010 14:38
JavaScript: Checking for offline data functionality
// Key/value storage
if ('localStorage' in window) { ... }
if ('sessionStorage' in window) { ... }
// SQL API
if ('openDatabase' in window) { ... }
// Offline application cache
if ('applicationCache' in window) { ... }
@bigsan
bigsan / dbinfo.sql
Created November 19, 2010 17:34
SQL: show databases info similar to sp_helpdb
SELECT
[name] database_name,
database_id,
SUSER_SNAME(owner_sid) owner_name,
recovery_model_desc,
collation_name,
[compatibility_level],
create_date
FROM sys.databases
@bigsan
bigsan / KillDatabaseProcess.sql
Created November 19, 2010 17:19
SQL: Kill processes related to some database
DECLARE @dbName nvarchar(max), @sql nvarchar(max)
SELECT @dbName = N'__DBNAME__', @sql = N''
SELECT @sql = @sql + N'KILL ' + CONVERT(nvarchar(max), spid) + ';'
FROM master..sysprocesses
WHERE dbid = DB_ID(@dbName)
--EXEC sp_executesql @sql
@bigsan
bigsan / changedbowner.sql
Created November 19, 2010 17:39
SQL: Change dbowner like sp_changedbowner
-- change dbowner of __DBNAME__ to sa
ALTER AUTHORIZATION ON DATABASE::[__DBNAME__] TO sa
@bigsan
bigsan / casperjs.ps1
Created April 20, 2012 13:47
PowerShell: rewrite casperjs from python to powershell
$PHANTOMJS_NATIVE_ARGS =
'cookies-file',
'config',
'disk-cache',
'ignore-ssl-errors',
'load-images',
'load-plugins',
'local-to-remote-url-access',
'max-disk-cache-size',
'output-encoding',
@bigsan
bigsan / gist:3826192
Created October 3, 2012 10:06
Less: CSS3 Ribbon
@size: 150px;
@ribbon-width: 210px;
@ribbon-height: 28px;
@offset: 13px;
@ribbon-left: (@size - @ribbon-width) / 2 + @offset;
@ribbon-top: (@size - @ribbon-height) / 2 - @offset;
.ribbon {
width: @size;
height: @size;