by alexander white ©
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Optimal bloom filter size and number of hashes | |
| # Tips: | |
| # 1. One byte per item in the input set gives about a 2% false positive rate. | |
| # 2. The optimal number of hash functions is ~0.7x the number of bits per item. | |
| # 3. The number of hashes dominates performance. | |
| # Expected number of items in the collection | |
| # n = (m * ln(2))/k; | |
| n = 300_000 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // keepDoingSomething will keep trying to doSomething() until either | |
| // we get a result from doSomething() or the timeout expires | |
| func keepDoingSomething() (bool, error) { | |
| timeout := time.After(5 * time.Second) | |
| tick := time.Tick(500 * time.Millisecond) | |
| // Keep trying until we're timed out or got a result or got an error | |
| for { | |
| select { | |
| // Got a timeout! fail with a timeout error | |
| case <-timeout: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "github.com/codegangsta/negroni" | |
| "github.com/gorilla/mux" | |
| "log" | |
| "net/http" | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "encoding/json" | |
| "fmt" | |
| "net/http" | |
| ) | |
| type test_struct struct { | |
| Test string |
When hosting our web applications, we often have one public IP
address (i.e., an IP address visible to the outside world)
using which we want to host multiple web apps. For example, one
may wants to host three different web apps respectively for
example1.com, example2.com, and example1.com/images on
the same machine using a single IP address.
How can we do that? Well, the good news is Internet browsers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 2014-03-04 | 15dfb8e6cc4111e3a5bb600308919594 | 11 | |
|---|---|---|---|
| 2014-03-06 | 81da510acc4111e387f3600308919594 | 61 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| import ftplib | |
| session = ftplib.FTP('example.com','username','password') | |
| file = open('cup.mp4','rb') # file to send | |
| session.storbinary('STOR '+'cup.mp4', file) # send the file | |
| file.close() # close file and FTP | |
| session.quit() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| protected void setupParent(View view) { | |
| //Set up touch listener for non-text box views to hide keyboard. | |
| if(!(view instanceof EditText)) { | |
| view.setOnTouchListener(new View.OnTouchListener() { | |
| public boolean onTouch(View v, MotionEvent event) { | |
| hideSoftKeyboard(); | |
| return false; | |
| } | |
| }); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "log" | |
| "net/http" | |
| ) | |
| func Log(handler http.Handler) http.Handler { | |
| return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |