You know how, in JavaScript, we can set a value to a variable if one doesn't, like this:
name = name || 'joe';This is quite common and very helpful. Another option is to do:
name || (name = 'joe');| /* | |
| Parallel processing with ordered output in Go | |
| (you can use this pattern by importing https://github.com/MarianoGappa/parseq) | |
| This example implementation is useful when the following 3 conditions are true: | |
| 1) the rate of input is higher than the rate of output on the system (i.e. it queues up) | |
| 2) the processing of input can be parallelised, and overall throughput increases by doing so | |
| 3) the order of output of the system needs to respect order of input | |
| - if 1 is false, KISS! |
| /* | |
| This snippet is an example of backpressure implementation in Go. | |
| It doesn't run in Go Playground, because it starts an HTTP Server. | |
| The example starts an HTTP server and sends multiple requests to it. The server starts denying | |
| requests by replying an "X" (i.e. a 502) when its buffered channel reaches capacity. | |
| This is not the same as rate-limiting; you might be interested in https://github.com/juju/ratelimit | |
| or https://godoc.org/golang.org/x/time/rate. |
| Array.prototype.shuffle = function () { | |
| var i, j, tempi, tempj; | |
| i = this.length; | |
| if ( i === 0 ) { | |
| return false; | |
| } | |
| while ( --i ) { | |
| j = Math.floor( Math.random() * ( i + 1 ) ); | |
| tempi = this[i]; |
| package main | |
| import ( | |
| "fmt" | |
| "labix.org/v2/mgo" | |
| "labix.org/v2/mgo/bson" | |
| "time" | |
| ) | |
| type Person struct { |
| HTTP status code symbols for Rails | |
| Thanks to Cody Fauser for this list of HTTP responce codes and their Ruby on Rails symbol mappings. | |
| Status Code Symbol | |
| 1xx Informational | |
| 100 :continue | |
| 101 :switching_protocols | |
| 102 :processing |
| <?php | |
| /** | |
| * Kelas untuk memanipulasi data yang berkaitan dengan rupiah. | |
| * | |
| * Catatan: Saya lupa darimana contoh fungsi terbilang awalnya! | |
| * | |
| * @version 0.0.1 | |
| * @author Anggiajuang Patria <[email protected]> | |
| * @copyright (c) 2009-2010 http://www.segellabs.com/ | |
| * @license http://www.gnu.org/licenses/gpl-3.0.txt |
You know how, in JavaScript, we can set a value to a variable if one doesn't, like this:
name = name || 'joe';This is quite common and very helpful. Another option is to do:
name || (name = 'joe');