Skip to content

Instantly share code, notes, and snippets.

View tossmilestone's full-sized avatar
:octocat:
Coding life

Shaw Ho tossmilestone

:octocat:
Coding life
  • Alauda
  • Nanjing, China
View GitHub Profile
@tossmilestone
tossmilestone / js_utils
Last active August 29, 2015 13:56
Useful functions extend js
//对Date的扩展,将 Date 转化为指定格式的String
//月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符,
//年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
//例子:
//(new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
//(new Date()).Format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18
Date.prototype.Format = function(fmt)
{ //author: meizz
var o = {
"M+" : this.getMonth()+1, //月份
@tossmilestone
tossmilestone / uri.js
Created February 27, 2014 04:29 — forked from jlong/uri.js
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
/*
* Scaffolding
* Basic and global styles for generating a grid system, structural layout, and page templates
* ------------------------------------------------------------------------------------------- */
.container
Sets a width of 940px which also centres the content (clears floated elements before/after)
.container-fluid
Sets a minimum width of 940px (clears floated elements before/after)
@tossmilestone
tossmilestone / kisscli.py
Created April 26, 2016 07:37 — forked from jpic/kisscli.py
Non blocking GNU readline usage example for python, proof of concept
import sys
from select import select
import socket
import readline
# HACK - python doesn't include a binding to rl_callback_read_char
import readline
import ctypes
rl_lib = ctypes.cdll.LoadLibrary("libreadline.so")
@tossmilestone
tossmilestone / pre-receive
Created July 26, 2016 06:43
Git push pep8 check
#!/bin/bash
COMMAND='flake8'
TEMPDIR=`mktemp -d`
while read oldrev newrev refname; do
files=`git diff --name-only ${oldrev} ${newrev}`
for file in ${files}; do
object=`git ls-tree --full-name -r ${newrev} | egrep "(\s)${file}\$" | awk '{ print $3 }'`
if [ -z ${object} ]; then continue; fi
@tossmilestone
tossmilestone / .cvimrc
Last active January 20, 2017 01:32 — forked from calorie/.cvimrc
.cvimrc
set nocncpcompletion
set nosmoothscroll
set nohud
set noregex
set noinsertmappings
set noautoupdategist
set nochangelog
set typelinkhints
set defaultnewtabpage
let scrollduration = 10
@tossmilestone
tossmilestone / gitlab_helper.py
Created May 31, 2017 03:02
A gitlab helper to simplify the batch operations on gitlab.
import argparse
import eventlet
import gitlab
import constants
eventlet.monkey_patch()
class GitlabHelper(object):
@tossmilestone
tossmilestone / subdir_cmd.sh
Last active May 31, 2017 03:03
Recursively enter sub directories and execute command
#!/bin/bash
for dir in ./*; do
if [ -d "$dir" ]; then
echo "Entering ${dir} ..."
pushd ${dir}
eval "$1"
popd
fi
done
wait
@tossmilestone
tossmilestone / pic.go
Created June 29, 2017 06:32
Answer of pic in go tour
package main
import "golang.org/x/tour/pic"
func Pic(dx, dy int) [][]uint8 {
z := make([][]uint8, dy)
for i := range z {
z[i] = make([]uint8, dx)
for j := range z[i] {
z[i][j] = uint8(i*j)
@tossmilestone
tossmilestone / words_count.go
Created June 30, 2017 09:04
Words count in go tour
package main
import (
"golang.org/x/tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
words := strings.Fields(s)
counts := make(map[string]int)