Skip to content

Instantly share code, notes, and snippets.

Avatar

Benjamin Eckel bhelx

View GitHub Profile
View base_62_converter.py
#!/usr/bin/env python
#
# Converts any integer into a base [BASE] number. I have chosen 62
# as it is meant to represent the integers using all the alphanumeric
# characters, [no special characters] = {0..9}, {A..Z}, {a..z}
#
# I plan on using this to shorten the representation of possibly long ids,
# a la url shortenters
#
@bhelx
bhelx / sql_canary.rb
Last active Apr 14, 2020
Pass a block of code to `while_enabled` to sniff out any SQL queries it might be making.
View sql_canary.rb
class SqlCanary
def self.enable!
Thread.current[:sql_canary] = true
end
def self.disable!
Thread.current[:sql_canary] = false
end
def self.enabled?
@bhelx
bhelx / recurly_bot.ex
Created Nov 30, 2016
Elixir Plug Cowboy Example
View recurly_bot.ex
defmodule RecurlyBot do
use Application
# See http://elixir-lang.org/docs/stable/elixir/Application.html
# for more information on OTP Applications
def start(_type, _args) do
import Supervisor.Spec, warn: false
# Define workers and child supervisors to be supervised
children = [
@bhelx
bhelx / test.php
Last active Sep 16, 2017
TLS Low Level Testing. You should expect to see it print TLS version 1.2.
View test.php
<?php
// This example is for testing php with libcurl
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.howsmyssl.com/a/check");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
View urban_access_test.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bhelx
bhelx / fetch.rb
Last active May 9, 2017
Recursively fetch Craigslist apartments using their map's json api
View fetch.rb
REGION = 'neworleans'
BASE_URL = "https://#{REGION}.craigslist.org"
parse_listings = lambda do |url|
results = JSON.parse Net::HTTP.get(URI(url))
results.first.each do |item|
if item.key? 'GeoCluster'
parse_listings.call("#{BASE_URL}#{item['url']}")
@bhelx
bhelx / binary_sort.rb
Last active Oct 10, 2016
BINARY SORT FOR EXERCISE.
View binary_sort.rb
class BinaryTree
attr_accessor :value, :left, :right
def insert(value)
if @value
if value < @value
@left ||= BinaryTree.new
@left.insert(value)
else
@bhelx
bhelx / process.js
Last active Mar 1, 2016
Fetch and resize geojson images concurrently using async.js
View process.js
"use strict";
let im = require('imagemagick');
let async = require('async');
let fs = require('fs');
let request = require('request');
let path = require('path');
let os = require('os');
let fetchAndProcess = (task, done) => {
@bhelx
bhelx / face_extract.rb
Last active Dec 30, 2015
recursively walk directory and extract faces
View face_extract.rb
require "opencv"
require "fileutils"
include OpenCV
detector = CvHaarClassifierCascade::load("./haarcascade_frontalface_alt.xml")
input_dir = ARGV[0]
output_dir = ARGV[1] || 'output'
FileUtils.mkdir_p(output_dir)
@bhelx
bhelx / safe_store.rb
Last active Dec 27, 2015
Securely store and retrieve a file from an external drive
View safe_store.rb
# This script allows securely storing and retrieving a file to USB drive using rbnacl
#
# Usage:
#
# 1) Generate a private key:
#
# ruby safe_store.rb --generate-key -k /Volumes/SAFEUSB/my_private_key.key
#
# 2) Write the ciphertext file to your drive (mine is named PATRIOT).
# This will write a file at /Volumes/PATRIOT/plain.txt.ctxt:
You can’t perform that action at this time.