Skip to content

Instantly share code, notes, and snippets.

@zhasm
zhasm / 0_reuse_code.js
Created May 7, 2014 03:18
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@zhasm
zhasm / getkey.py
Created March 18, 2014 06:15
get keypress without enter
def getkey():
"get key press without Enter"
import termios, sys, os
fd = sys.stdin.fileno()
old = termios.tcgetattr(fd)
new = termios.tcgetattr(fd)
new[3] = new[3] & ~TERMIOS.ICANON & ~TERMIOS.ECHO
new[6][TERMIOS.VMIN] = 1
@zhasm
zhasm / snippet.py
Last active October 4, 2016 07:36
python snippets
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
#author: rex
#blog: http://iregex.org
#
import re
from os.path import dirname as dirname
@zhasm
zhasm / my.sql
Last active August 29, 2015 13:56
brew install mysql
### mysql
A "/etc/my.cnf" from another install may interfere with a Homebrew-built
server starting up correctly.
To connect:
mysql -uroot
To have launchd start mysql at login:
ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
Then to load mysql now:
@zhasm
zhasm / new_mac.md
Last active December 9, 2016 00:46
New Mac Configration
@zhasm
zhasm / .user.el
Last active January 4, 2016 17:09
keyboard.shortcuts
;;; rex zone
;; show linum by default
(global-linum-mode t)
(setq linum-format " %03d ")
(setq display-time-day-and-date t)
(setq display-time-24hr-format t)
@zhasm
zhasm / ff.url.php
Created December 24, 2013 10:35
url regex.
const URL_REGEXP_PROTOCOL = '(?:(http|https):\/\/)';
const URL_REGEXP_USER = '(?:[^\/]+?(?::[^\/]+?)?@)?';
const URL_REGEXP_HOST = '(?:(?:(www\.)?(?:[\w\-]+\.)+(?:[a-z]{2,4}))|(?:(?:\d{1,3}\.){3}\d{1,3}))';
const URL_REGEXP_PORT = '(?::\d{1,5})';
const URL_REGEXP_QUERY = '(?:\/[\w\-\?\.\=\&\+\%\[\]\/#;@:~!]*)';
@zhasm
zhasm / curlicue
Created December 12, 2013 02:41
1,准备:将curlicue, curlicue-setup 保存到可识别的 bin 路径下,+x;将 msg 函数放到 ~/.bashrc 里,souce 一下; 2,初始化:执行 curlicue-setup ,按照提示操作; 3,发消息:msg NAME MESSAGE
#!/bin/sh
# Curlicue - an OAuth wrapper for curl
#
# Copyright © 2010 Decklin Foster <decklin@red-bean.com>
# Please see README for usage information and LICENSE for license.
# Because HTTP responses from the OAuth "dance" will be percent-encoded,
# and we want to round-trip this data, we require that credentials files
# are also percent-encoded. Therefore, no decoding is done here. $1 is
@zhasm
zhasm / gist:7819691
Created December 6, 2013 07:01
Gohan [49601]
Process: Gohan [49601]
Path: /Applications/Gohan.app/Contents/MacOS/Gohan
Identifier: me.imach.gohanmac
Version: 1.0 (1.0)
App Item ID: 735180013
App External ID: 86782801
Code Type: X86-64 (Native)
Parent Process: launchd [203]
Responsible: Gohan [49601]
User ID: 501
@zhasm
zhasm / p_99.js
Last active December 29, 2015 05:29
parse 99 只含有数字的参数,数值可能从 -99 到 99 之间变换,如何用正则匹配到整个字符串,从而完成在字符串末尾加上一个“度”字呢
###
#所需的函数:
p_99, 使用js 内置的parseInt,做比较;
re_99,使用正则式做匹配测试。
如果只想匹配 2 位的数字,忽略1位的数字,将 [0-9]{1,2} 改为 [0-9]{2} 即可。
###
p_99 = (degree) ->