Archive for the ‘ Uncategorized ’ Category

An interesting bit of math

http://plus.maths.org/content/os/issue26/features/sautoy/index

Every time you use your credit card on the internet to buy a ticket to see Real Madrid play, your account is kept secret from hackers thanks to the power of prime numbers. Prime numbers have become the locks that preserve the secrets that are racing through the electronic shopping mall.

Each e-business chooses two big primes, p and q, which they keep secret. The product of these primes, N=pxq, is made public. A calculation using N encrypts your credit card, but the only way to undo the calculation and decrypt the secret message is to know the secret primes p and q. Cracking codes is the same as cracking the public number N into its prime building blocks. It’s a bit like a chemist who wants to know the atoms inside a compound. Although chemists have solved their problem, mathematicians lack any fast way to do this prime-number spectroscopy – to the relief of internet cryptographers.

Quick list of words I misspell

I keep a list of words that I commonly typo so I can learn how to spell them over time. It’s good to just have something like this echo at your in your .bashrc so every time you open a new terminal tab, you’ll see the right way to spell them and eventually you’ll read them enough to learn.

ambiguous
anonymity
authoritative
believe
character
convenience
corresponding
decommissioned
definitely
degradation
discipline
embarrassment
figuratively
frustrated
guarantee
interpretive
license
maintenance
maneuver
miniature
possession
privilege
receipt
receive
residual
ridiculous
weird

Shortest bit of JS to hide text after [time]

I was trying to figure out the least amount of code that would render in a browser for 15ms, which is supposedly about the shortest time that subliminal advertising works. Here is what I came up with:

<script>
function s(){setTimeout(function(){document.getElementById("m").style.display="none";},15);}
</script>
<body onload=s()>
<div id=m>Test

If you can get it even shorter, leave a comment!

Python retreive SQLite results as dictionary of lists

This is an interesting block of code that I just wrote while working on Beaker, the statistics package that goes along with MadScience

# numbers that are floating-point and must be handled as such
floats = ['up', 'time', 'data', 'resptime', 'trans', 'bw', 'concur', 'long', 'short']
# ditto for integers
ints = ['hits', 'ok', 'fail']

# init a new dictionary
mydict = {}

# for every item in the combination of the integers and the floats, create a key for it and assign the value to a blank list
for i in floats + ints:
    mydict[i] = []

# for every row returned by the SQLite query, iterate through all the integers, then all the floats
# for each different named value, go to the dict key that matches and add something to the value of that key, which is a list
# the value should be converted to the respective type and the key coming from the SQLite results (the column name in the DB) matches the names of our keys and thus can be iterated 1:1
for row in cursor.execute(myquery):
    for key in floats:
        mydict[key].append(float(row[key]))
    for key in ints:
       mydict[key].append(int(row[key]))

R1Wrangler

I’m working on a full-blown webapp to manage our R1Soft CDP backup server cluster. We have around 1,000 servers and needed a good way to keep track of what backup server(s) they’re on, when they’re getting backed up, if they’re failing, disk space used, if they failed backups previously, etc. I also wanted to have a way to easily add backups to any existing backup server, so I created R1Wrangler: https://github.com/ip2k/R1-Wrangler . It’s still a work in progress and the DB schema isn’t even on the final revision yet, but it’s getting there and should be useful if you want to dive in to the R1Soft CDP Server 2.x XMLRPC API, OO PHP, normalised database schema, etc.

Clicky kitty to check it out!

My .vimrc

Still a work in progress. I don’t use vim all the time, but more and more I see it as a huge time saver.

" General config
set nocompatible
set nowrap
set listchars=tab:>-,trail:-

set nu
set list
set showmatch
set autowrite
filetype plugin indent on
syntax on
set ruler

"make it so that jk, instead of navigating across actual lines, allows you
"to scroll up/down visual lines... so if you have a really long wrapped line,
"you can actually scroll down through it
nnoremap <Down> gj
nnoremap <Up> gk

" Customizing indentation so it just does what I expect it to
set tabstop=8
set softtabstop=4
set shiftwidth=4
set expandtab
set shiftround
set smarttab
set autoindent
set smartindent
set cindent
filetype indent on

" set shift-tab to unindent
imap <S-Tab> <C-o><<

" C-specific configuration
set cino=+0.5s
autocmd FileType c,cpp   set cindent

" Syntax highlighting for non-standard files
autocmd BufNewFile,BufRead *.thrift set filetype=c
" viki config
" au BufNewFile,BufRead *.viki :VikiMinorMode
" let g:vikiUseParentSuffix = 1
Page 1 of 41234