Skip to content

Instantly share code, notes, and snippets.

View CatTail's full-sized avatar
😑

Chiyu Zhong CatTail

😑
View GitHub Profile
@CatTail
CatTail / genschema.js
Last active August 29, 2015 13:57
Handy script to auto generate mongoose schema from existing data
var prefix = Math.random();
function parse(obj) {
var key, value, type, schema;
type = obj.constructor.name;
switch (type) {
case 'Object':
schema = {};
for (key in obj) {
value = parseKey(key, obj);
if (value !== undefined) schema[key] = value;
@CatTail
CatTail / reload-audio
Created May 12, 2014 03:15
OS X休眠唤醒后无声音
# 重启声音驱动
sudo kextunload /System/Library/Extensions/AppleHDA.kext
sudo kextload /System/Library/Extensions/AppleHDA.kext
@CatTail
CatTail / minus-one.js
Created July 3, 2014 10:07
handy operator to check if result is -1
var isMatch = ~'this is a text'.indexOf('IS');
@CatTail
CatTail / httpdump
Created September 16, 2014 14:31
Dump http connection via tcpdump
tcpdump 'tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)'
@CatTail
CatTail / enc
Created September 16, 2014 23:09
Encrypt & Decrypt single message with openssl AES-256
#! /bin/bash
# usage: enc [-d] <message>
if [ $# == 2 ]; then
echo $2 | openssl enc -e -aes-256-cbc -a -salt $1
else
echo $1 | openssl enc -e -aes-256-cbc -a -salt
fi
@CatTail
CatTail / parser.js
Last active August 29, 2015 14:06
Simple apache nginx parser with NodeJS
var patterns = {
'[': '\\[([^\\]]+)\\]',
'![': '[^\\[]+',
'"': '"([^"]+)"',
'!"': '[^"]+',
'default': '(\\S+)', // default pattern
'!default': '\\s+'
};
function Parser(format) {
@CatTail
CatTail / read.c
Last active August 29, 2015 14:07
block reading
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/uio.h>
int main(void)
{
char buf[80];
@CatTail
CatTail / nonblock-read.c
Last active August 29, 2015 14:07
non-block reading
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/uio.h>
int main(void)
{
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
int max(int a, int b) {
return a > b ? a : b;
}
int main()
@CatTail
CatTail / epoll.c
Last active August 29, 2015 14:07
#include <netinet/in.h>
#include <sys/socket.h>
#include <netdb.h>
#include <fcntl.h>
#include <sys/epoll.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <resolv.h>