Skip to content

Instantly share code, notes, and snippets.

View elliotthilaire's full-sized avatar

Elliott Hilaire elliotthilaire

View GitHub Profile
@elliotthilaire
elliotthilaire / range_map.ex
Last active April 13, 2019 10:51
Create a function that maps an input to a specific range
defmodule RangeMap do
def to_function(in_min, in_max, out_min, out_max) do
difference_in = in_max - in_min
difference_out = out_max - out_min
factor = difference_out / difference_in
midpoint_in = (in_min + in_max) / 2
midpoint_out = (out_min + out_max) / 2
constant = midpoint_out - midpoint_in
@elliotthilaire
elliotthilaire / branch-compare.sh
Last active January 12, 2019 05:43
A bash script to run a command against different branches or commits automatically
#!/bin/bash
# Usage:
# ./compare-branches.sh "./some-command arg-1 arg-2" branch-1 branch-2
#
# https://twitter.com/elliotthilaire/status/1083859808086720512
# Thanks to @schneems, @tosbourn, and @matthewrudy for their input.
current_branch=$(git symbolic-ref --short HEAD)
ffmpeg -r 12.5 -pattern_type glob -i '*.JPG' -s 1920:1440 -vcodec libx264 timelapse.mp4
ffmpeg -r 30 -start_number 71543 -i G00%d.JPG -s 1920:1440 -vcodec libx264 timelapse.mp4
// ATtiny85 Night Light
void setup() {
pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
}
void loop() {
if (digitalRead(2) == HIGH) {
@elliotthilaire
elliotthilaire / fetching-records-with-sequel-gem-in-order-of-array.rb
Created May 17, 2017 16:19
How to fetch records in order with an array of ids using the sequel gem
# http://sequel.jeremyevans.net/rdoc/classes/Sequel/SQL/Builders.html#method-i-case
# http://sequel.jeremyevans.net/rdoc/classes/Sequel/Dataset.html#method-i-order
# http://www.justinweiss.com/articles/how-to-select-database-records-in-an-arbitrary-order/
# Given an array of ids. How can we retrieve the records in that order.
# Using the Sequel gem.
# SELECT * FROM items WHERE id IN (2, 3, 1, 4) ORDER BY
# CASE id
# WHEN 2 THEN 0
@elliotthilaire
elliotthilaire / Dockerfile
Created February 28, 2017 15:04
`yarn install` with in alpine docker image with apk
COPY package.json /usr/src/app/
COPY yarn.lock /usr/src/app/
# TODO: replace custom repository when yarn is no longer in edge/community
RUN apk add yarn --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/community/ && \
yarn install && \
apk del yarn
@elliotthilaire
elliotthilaire / file_upload_form.html.erb
Created February 27, 2017 15:47
Upload multipart file with ajax
<%= form_tag project_assets_path(project), multipart: true, class: 'upload-form' do %>
<%= file_field_tag 'file' %>
<%= submit_tag 'Upload' %>
<% end %>
@elliotthilaire
elliotthilaire / intializers-assets.rb
Created February 21, 2017 13:09
Precompile assets based on controller_path
# http://guides.rubyonrails.org/asset_pipeline.html#controller-specific-assets
Dir[Rails.root.join('app/controllers/**/*_controller.rb')].each do |path|
controller_path = path.match(/controllers\/(.*)_controller.rb/)[1]
Rails.application.config.assets.precompile += ["#{controller_path}.js", "#{controller_path}.scss"]
end
@elliotthilaire
elliotthilaire / task.js
Last active February 21, 2017 08:50
Playing with EventEmitter
const EventEmitter = require('events')
const myEmitter = new EventEmitter()
function start () {
myEmitter.emit('ready')
myEmitter.emit('set')
myEmitter.emit('go')
}
#!/bin/sh
# To reinstall this script in the same or another git repo run:
# curl -sSL https://gist.github.com/elliotthilaire/5e56566b75781b8cd9d2/raw/pre-commit > .git/hooks/pre-commit; chmod +x .git/hooks/pre-commit
# check that pronto is installed first
hash pronto 2>/dev/null || {
echo >&2 "Pronto is not installed. Install with 'gem install pronto pronto-rubocop'";
echo >&2 "Find other pronto runners at https://github.com/mmozuras/pronto#runners";
exit 0;