Skip to content

Instantly share code, notes, and snippets.

View madis's full-sized avatar
🧑‍💻
code mode

Madis Nõmme madis

🧑‍💻
code mode
View GitHub Profile
@madis
madis / serve.rb
Last active July 4, 2017 10:03
Simple Webrick server
#!/usr/bin/env ruby
require 'webrick'
class Servlet < WEBrick::HTTPServlet::FileHandler
PORT = 4200
INDEX_FILE = 'index.html'
ROOT_PATH = File.expand_path(__dir__) # Folder of current file
def do_GET(request, response)
#!/usr/bin/env ruby
class GraphGenerator
# Returns list of edges for n-vertex complete graph
#
# Example:
# GraphGenerator.generate(4)
# [1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4]
def self.generate(count)
if count == 1
@madis
madis / copy_over_ssh.sh
Created October 20, 2016 09:47
Copy multiple small files from remote machine using ssh & tar
# From http://meinit.nl/using-tar-and-ssh-to-efficiently-copy-files-preserving-permissions
ssh user@machine-where-precious-data-is "tar czpf - /some/important/data" | tar xzpf - -C /new/root/directory
@madis
madis / flatten.rb
Created October 16, 2016 22:51
Flatland
def flatten(input, output=[])
input.each do |e|
if e.is_a? Array
output += flatten(e)
else
output.push e
end
end
output
end
def build_tree(root_id:)
root_row = db_find(id: root_id)
root_node =
{
id: root_id,
text: root_row[:text]
}
add_children(root_node, db_find_children(parent_id: root_id))
root_node
end
@madis
madis / thread_explosion.rb
Created September 7, 2016 13:53
Testing ruby loading in multiple threads
require 'thwait'
$LOAD_PATH << '/Users/madisnoemme/code/etventure/rbn-be-api'
threads = 10000.times.map {
print "."
Thread.new {
require_relative './rbn/service/xml/mapping'
require_relative './rbn/service/xml/mappings'
}
}
Settings
@madis
madis / gist:f07bf068e6b7fc5be7cc
Created June 29, 2015 08:05
Remove all docker images
docker images | tail -n+2 | awk '{print $3}' | xargs -L1 docker rmi
@madis
madis / getUserMediaBug.js
Created June 11, 2015 17:06
Firefox getUserMedia bug with quick consecutive calls
navigator.mozGetUserMedia({video: true, audio: false}, function(s) {window.zeVideoOnly = s}, function() {}); navigator.mozGetUserMedia({video: true, audio: true}, function(s) {window.zeVideo = s}, function() {})
@madis
madis / data_uri_to_blob.js
Created May 14, 2015 08:26
Data URI to Blob
// From http://stackoverflow.com/questions/6850276/how-to-convert-dataurl-to-file-object-in-javascript
function dataURItoBlob(dataURI) {
if(typeof dataURI !== 'string'){
throw new Error('Invalid argument: dataURI must be a string');
}
dataURI = dataURI.split(',');
var type = dataURI[0].split(':')[1].split(';')[0],
byteString = atob(dataURI[1]),
byteStringLength = byteString.length,
arrayBuffer = new ArrayBuffer(byteStringLength),