November 25, 2014

How to make IE not cache your golang web app responses

var w http.ResponseWriter
w.Header().Set("cache-control", "priviate, max-age=0, no-cache")
w.Header().Set("pragma", "no-cache")
w.Header().Set("expires", "-1")

November 24, 2014

Clear windows event log

Run this following line in PowerShell as Admin:

wevtutil el | Foreach-Object {Write-Host "Clearing $_"; wevtutil cl "$_"}

November 19, 2014

Read godoc in vim using Shift K

Add the following to your ~/.vim/ftplugin/go.vim (the key here is to use <cfile> not <cword>)

fun! ReadMan()
  " Assign current file under cursor to a script variable:
  let s:man_word = expand('<cfile>')
  :exe ":Godoc " . s:man_word
endfun
" Map the K key to the ReadMan function:
map K :call ReadMan()<CR>

=======UPDATE========
Had a better way for this:

1. Create a file in your ~/bin called godoc.sh with the following content:
#!/bin/sh
fullpkg=`gawk -v "cmd=$1" '
{ FS="/" }
{
        if ($NF==cmd || $0 ==cmd){
                printf("%s",$0);
                exit;
        }
}' ~/bin/gopkg-list.txt`
echo -n $fullpkg

2. Create a text file in ~/bin/gopkg-list.txt with the following contents:
log/syslog
unicode/utf8
unicode/utf16
testing
hash/crc64
hash/adler32
hash/fnv
hash/crc32
archive/zip
archive/tar
expvar
mime
reflect
crypto/des
crypto/sha1
crypto/subtle
crypto/aes
crypto/md5
crypto/cipher
crypto/rand
crypto/ecdsa
crypto/tls
crypto/sha512
crypto/x509
crypto/sha256
crypto/elliptic
crypto/hmac
crypto/rsa
crypto/x509/pkix
crypto/rc4
crypto/dsa
flag
strings
sync
os/user
os/signal
os/exec
os
fmt
syscall
time
runtime/pprof
runtime/cgo
runtime/debug
runtime/race
net/http/httputil
net/http/cookiejar
net/http/fcgi
net/http/pprof
net/http/cgi
net/http/httptest
net/rpc/jsonrpc
net/mail
net/http
net/textproto
net/url
net/rpc
net/smtp
io/ioutil
math
database/sql/driver
database/sql
mime/multipart
bytes
errors
sort
bufio
encoding
log
path/filepath
index/suffixarray
net
crypto
sync/atomic
go/printer
go/doc
go/scanner
go/ast
go/parser
go/token
go/build
go/format
unicode
image
io
runtime
html/template
regexp
html
container/ring
container/list
container/heap
hash
path
regexp/syntax
text/template/parse
text/tabwriter
text/template
text/scanner
strconv
testing/quick
testing/iotest
compress/flate
compress/zlib
compress/lzw
compress/bzip2
compress/gzip
image/color
image/draw
image/color/palette
image/png
image/gif
image/jpeg
encoding/base64
encoding/base32
encoding/xml
encoding/asn1
encoding/pem
encoding/ascii85
encoding/csv
encoding/hex
encoding/json
encoding/binary
encoding/gob
debug/pe
debug/plan9obj
debug/dwarf
debug/elf
debug/gosym
debug/macho
math/rand
math/big
math/cmplx

3. In your ~/.vim/ftplugin/go.vim, add the following:
fun! ReadMan()
  " Assign current file under cursor to a script variable:
  let s:man_word = expand('<cword>')
  let s:full_word = system('~/bin/godoc.sh '. s:man_word)
  :exe ":Godoc " . s:full_word
endfun
" Map the K key to the ReadMan function:
map K :call ReadMan()<CR>

This will take the keyword under cursor, expanded using the shell script, and call :Godoc on it. This takes care of subpackages

November 14, 2014

ios validate self signed certificate

http://stackoverflow.com/questions/10979922/ios-and-ssl-unable-to-validate-self-signed-server-certificate

Quote:


I did figure out how to resolve this issue.
I ended up comparing the client and server trust certificates, byte-by-byte. Although there could be another way to resolve such issues of self-signed certificate, but for this solution did work. Here is how I'm doing comparison of the client and server certificates, byte-by-byte, using their CFData objects(you can also reference 'AdvancedURLConnections' example code provided by Apple):
success = NO;
        pServerCert = SecTrustGetLeafCertificate(trust);
        if (clientCert != NULL) {
            CFDataRef       clientCertData;
            CFDataRef       serverCertData;

            clientCertData = SecCertificateCopyData(clientCert);
            serverCertData   = SecCertificateCopyData(pServerCert);

            assert(clientCertData != NULL);
            assert(serverCertData   != NULL);

            success = CFEqual(clientCertData, serverCertData);

            CFRelease(clientCertData);
            CFRelease(serverCertData);
        }
        if (success) {
            [[challenge sender] useCredential:credential forAuthenticationChallenge:challenge];
            [self printLogToConsole:@"Success! Trust validation successful."];
        } else {
            [self printLogToConsole:@"Failed! Trust evaluation failed for service root certificate.\n"];
            [[challenge sender] cancelAuthenticationChallenge:challenge];
        }
Hope this will help someone, who is looking for solution of similar issue,

November 12, 2014

the ffmpeg command to explode video into still images

ffmpeg.exe -i IMG_0278.MOV -ss 0  -t 1 -f image2 -sameq -vcodec mjpeg "img-%03d.jpg"

-ss: start time, 0 means starting at 0 second mark
-t : number of seconds to explode


November 6, 2014

vim and error list

If you have text file that contains the list of errors with line positions, you can tell vim to use that to help you navigate through the list.

1. Edit the list to the following format (suppose it is named "errors.txt")
    xxxx.c:123: Warning/Error/Info rest-of-the-text
    where
    xxxx.c is the source code file name
    123 is the line number

2. vim -q errors.txt

3. now you can type ":cw" to open the "quickfix" window which list the errors, and use ":cn" and ":cp" to go through them. Mapping these to a short cut key will make life easier. I map mine to Ctrl-j and Ctrl-k for down and up (copy and the paste the following to your ~/.vimrc file)

    map <C-J> :cn<CR>
    map <C-K> :cp<CR>

November 5, 2014

check ip address owner

For an U.S IP address, you can go to the following site:

http://whois.arin.net

and put the IP address in the search box of top right corner, and you can get more info on it.

Once you find the owner, you can click on "Related Networks" to find all the IP addresses that owner owns.

November 3, 2014

How to dump Mac OS X dns cache

DNS cache information is not managed by Directory Services, contrary to popular opinion on this site. It's managed by mDNSResponder, and the man page contains the answer to your question:


A SIGINFO signal will dump a snapshot summary of the internal state to /var/log/system.log:

   % sudo killall -INFO mDNSResponder