This file contains 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
/* | |
The first 12 digits of pi are 314159265358. We can make these digits into an | |
expression evaluating to 27182 (first 5 digits of e) as follows: | |
3141 * 5 / 9 * 26 / 5 * 3 - 5 * 8 = 27182 | |
or | |
3 + 1 - 415 * 92 + 65358 = 27182 | |
Notice that the order of the input digits is not changed. Operators (+,-,/, | |
or *) are simply inserted to create the expression. |
This file contains 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
#ruby 2.3.1 recomended | |
class Graph | |
attr_reader :graph, :nodes, :previous, :distance #getter methods | |
INFINITY = 1 << 64 | |
def initialize | |
@graph = {} # the graph // {node => { edge1 => weight, edge2 => weight}, node2 => ... | |
@nodes = Array.new | |
end |
This file contains 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
// Support: http://caniuse.com/promises | |
function Http () { | |
/** | |
* Helper for http calls | |
* @param method | |
* @param url | |
* @param data | |
* @returns {Promise} | |
*/ | |
function makeRequest(method,url,data) { |
This file contains 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
#!/bin/env ruby | |
# lazy hack from Robert Klemme | |
module Memory | |
# sizes are guessed, I was too lazy to look | |
# them up and then they are also platform | |
# dependent | |
REF_SIZE = 4 # ? | |
OBJ_OVERHEAD = 4 # ? |
This file contains 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
literally always have to look up the meaning of :limit in migrations when it comes to integer values. Here's an overview. Now let's memorise it (oh, this works for MySQL, other databases may work differently): | |
:limit Numeric Type Column Size Max value | |
1 tinyint 1 byte 127 | |
2 smallint 2 bytes 32767 | |
3 mediumint 3 byte 8388607 | |
nil, 4, 11 int(11) 4 byte 2147483647 | |
5..8 bigint 8 byte 9223372036854775807 | |
Note: by default MySQL uses signed integers and Rails has no way (that I know of) to change this behaviour. Subsequently, the max. values noted are for signed integers. |