Skip to content

Instantly share code, notes, and snippets.

View sokrato's full-sized avatar

Sokrato sokrato

  • Alibaba
  • HangZhou, China
View GitHub Profile
EGIN {
FIELD_LIST = "Field1,Field2,Field3"; # fields definition, in order
split(FIELD_LIST, fields, ",");
}
{
pos = find(fields, $1);
if (pos == 0) {
print("unexpected field " $1);
exit 1;
@sokrato
sokrato / postfix_calculator.py
Last active March 14, 2016 11:03
Postfix calculator implementation in Python, infix to postfix transformation, for theories, see http://www.smccd.net/accounts/hasson/C++2Notes/ArithmeticParsing.html
'''
Infix calculator
First tokenize infix expression,
then transform it into postfix,
then calculate it.
E.g.:
9 - 5 + 2 * 3
=> 9 5 - 2 3 * +
'''
import re
@sokrato
sokrato / wc.c
Created November 10, 2013 13:40
word counting program in C
#include<stdio.h>
#include<string.h>
#include<ctype.h>
struct node{
int num;
char *p;
struct node *next;
};
@sokrato
sokrato / oop.js
Created October 18, 2013 11:45
JavaScript Inheritance
var Base = {
create: function(attrs){
var o=this.clone();
o.init(attrs);
return o;
},
clone: function() {
var o={};
for(var i in this)
if (this.hasOwnProperty(i))
@sokrato
sokrato / exclude.sh
Created April 20, 2012 04:33
exclude some pub key files
#authorized keys file name
AK=authorized_keys
#enabled pub key dir
ENABLED=enabled_keys
#disabled pub key dir
DISABLED=disabled_keys
if [[ $# = 0 ]]
then
printf "Usage:\n %s to_be_removed.pub\n" "$0"