Skip to content

Instantly share code, notes, and snippets.

View yao2030's full-sized avatar

yao2030 yao2030

  • Shanghai, China
View GitHub Profile
@yao2030
yao2030 / ex01.sh
Created September 26, 2013 07:54
ex01.sh
#!/usr/bin/sh
while true
do
ip=`hostname -i`
date=`date +"%d/%b/%Y:%k:%M:%S %z"`
r=$RANDOM;
random=$(($r+10000000))
time=$[RANDOM % 200 + 10]
echo "[$ip [$date] \"$random\" time=${time}ms]";
done
@yao2030
yao2030 / ex01(modified).sh
Created September 26, 2013 07:54
ex01.sh for ex02.sh
#!/usr/bin/sh
pipe=/tmp/out
#if [[ ! -p $pipe ]]; then
# echo "Reader not running"
# exit 1
#fi
while true
do
ip=`hostname -i`
@yao2030
yao2030 / ex02.sh
Created September 26, 2013 07:52
ex02.sh
#!/usr/bin/sh
pipe=/tmp/out
#if [[ ! -p $pipe ]]; then
# echo "Reader not running"
# exit 1
#fi
while true
do
ip=`hostname -i`
@yao2030
yao2030 / capture.pl
Created September 18, 2013 10:23
capture
#/usr/bin/perl
##Copyright (C) 2013 by Yours truly
$_ = "Hello there, neighbor";
if (/(\S+) (\S+), (\S+)/)
{
print "words were $1 $2 $3\n";
}
@yao2030
yao2030 / any.pl
Created September 18, 2013 10:15
barney & fred
#/usr/bin/perl
##Copyright (C) 2013 by Yours truly
#
$_ = "I saw Barney\ndown at the bowling alley\nwith Fred\nlast night.\n";
if (m{
barney # the little guy
.* # anthing in between
fred # the loud guy
}six)
@yao2030
yao2030 / ex12-3.pl
Created September 18, 2013 03:43
programming perl
#!/usr/bin/perl
use strict;
print "Looking for my files that are both writable and executable\n";
die "No file specified\n" unless @ARGV;
my @myfile;
foreach my $file (@ARGV)
@yao2030
yao2030 / dp.py
Created April 14, 2013 14:18
Dynamic programming in Python, MIT Intro to CS Programming, LECTURE 12 & 13
# def fib(n):
# global numCalls
# numCalls += 1
# print 'fib called with', n
# if n == 0 or n == 1:
# return 1
# else:
# return fib(n-1) + fib(n-2)
# # numCalls = 0
@yao2030
yao2030 / nested-lets.scm
Created April 12, 2013 01:58
SICP Exercise 4.7
(define (let*->nested-lets clauses)
(if (null? (car clauses))
(cadr clauses)
(list 'let (list (caar clauses))
(let*->nested-lets (cons (cdar clauses)
(cdr clauses))))))
1 ]=> (let*->nested-lets '(((x 3) (y (+ x 2)) (z (+ x y 5))) (* x z)))
@yao2030
yao2030 / ex46.scm
Created April 12, 2013 01:26
Derived expressions for Let, SICP exercise 4.6
(define (let? exp)
(tagged-list? exp 'let))
(define (let-clauses exp)
(cdr exp))
(define (get-parameters clauses)
(if (null? (car clauses))
'()
(cons (caaar clauses)
@yao2030
yao2030 / ex45.scm
Last active December 16, 2015 02:09
SICP Exercose 4.5, without peeking at others's code
(define (expand-clauses clauses)
(if (null? clauses)
'false ; no else clause
(let ((first (car clauses))
(rest (cdr clauses)))
(if (cond-else-clause? first)
(if (null? rest)
(sequence->exp (cond-actions first))
(error "ELSE clause isn't last -- COND->IF"
clauese))