Skip to content

Instantly share code, notes, and snippets.

View rebase-master's full-sized avatar
🚂
Diving into Rails 7

Mansoor Khan rebase-master

🚂
Diving into Rails 7
View GitHub Profile
@danyim
danyim / findEq.js
Last active July 10, 2019 21:14
Brute-force algorithm for finding a valid equation for a given string of numbers
/*
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.
@jithinabraham
jithinabraham / graph.rb
Last active January 5, 2024 03:31
Dijkstra's algorithm implemented in ruby
#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
@manar007
manar007 / Http.js
Last active February 11, 2020 06:24
Promises with vanilla js, helper http function
// Support: http://caniuse.com/promises
function Http () {
/**
* Helper for http calls
* @param method
* @param url
* @param data
* @returns {Promise}
*/
function makeRequest(method,url,data) {
@camertron
camertron / measure.rb
Created June 15, 2012 22:48
Measure the memory taken by a Ruby object (by Robert Klemme)
#!/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 # ?
@stream7
stream7 / migration_integer_limit_option
Created July 7, 2011 14:09
Rails migrations integer :limit option
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.