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
# simple recursive algorithm | |
def binary_search_recursive(ary, value) | |
return nil if ary.empty? | |
pivot = ary.length / 2 | |
pivot_value = ary[pivot] | |
if pivot_value < value | |
binary_search_recursive(ary[(pivot + 1)..-1], value) | |
elsif pivot_value == value | |
return pivot | |
else |
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
// dimensions should be the number of dimensions your points have | |
// points should be an array of arrays, the inner arrays representing points | |
// depth shouldn't be passed, it's used internally | |
// example: | |
// var tree = kdtree(2, [[1,2], [3,4], [5,6]]); | |
function kdtree(dimensions, points, depth) { | |
depth = depth || 0; | |
var axis = depth % dimensions, | |
node = {axis: axis}; |
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
require "socket" | |
# edit these | |
socket_path = "tmp/sockets/unicorn.sock" | |
host = "example.com" # HTTP 1.1 requires a Host header | |
path = "/" | |
# connect | |
sock = UNIXSocket.new(socket_path) |
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
require "net/http" | |
# fetcher = FeedCrawler::URLFetcher.new("example.com") | |
# paths = ["/foo", "/bar", "/baz", "/qux"] | |
# results = fetcher.fetch(paths) | |
# results.each do |result| | |
# puts result | |
# end | |
# | |
class URLFetcher |
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/env ruby | |
require "socket" | |
# This is a simple preloader for Ruby apps. | |
# Usage: | |
# Put this file somewhere in your PATH, named 'ruby_preloader' and make sure | |
# it's executable. | |
# Add whatever you need to load your app environment to a .preload.rb in the | |
# base directory of your project. | |
# Add #!/usr/bin/env ruby_preload as the first line of any script you want to |
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
source "https://rubygems.org" | |
gem "ruby-opencv" |
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
require "net/https" | |
require "json" | |
GITHUB_OAUTH_TOKEN = <YOUR OAUTH TOKEN HERE> | |
GITHUB_ORG_NAME = <YOUR ORG> | |
def api_request(http, path) | |
request = Net::HTTP::Get.new(path) | |
request["Authorization"] = "token #{GITHUB_OAUTH_TOKEN}" | |
response = http.request(request) |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Test</title> | |
<script src="tint.js"></script> | |
<script> | |
document.addEventListener("DOMContentLoaded", function () { | |
document.querySelectorAll("img").forEach(function (img) { | |
img.addEventListener("load", function () { | |
tint(img); |
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
#!/bin/bash | |
if [[ -z "$1" ]]; then | |
echo "usage: $0 [user@]hostname" | |
exit 1 | |
fi | |
ssh -ND 1080 "$1" & | |
PID=$! |
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
require "sinatra/base" | |
class App < Sinatra::Base | |
using SomeRefinementModule | |
# hack to enable refinements in templates | |
module CompiledTemplates | |
_binding = binding # get the current binding | |
# add a class_eval method to the binding that does an eval in the binding |