Skip to content

Instantly share code, notes, and snippets.

View elliotthilaire's full-sized avatar

Elliott Hilaire elliotthilaire

View GitHub Profile
@elliotthilaire
elliotthilaire / bash-change-colour-on-ssh
Last active August 29, 2015 14:09
Change the visual theme of Terminal.app during an SSH connection
# Add this to your .bash_profile file.
# Assumes you are running a OSX, using the default Terminal.app, and have Homebrew (for its custom theme) installed.
# Inspiration from: https://gist.github.com/porras/5856906
function colorssh() {
# Change the theme of Terminal.app
osascript -e "tell application \"Terminal\" to set current settings of front window to settings set \"Homebrew\"";
# Run the `ssh` command
ssh $*
#!/bin/bash
APP_NAME="your-app-name-goes-here"
APP_PATH=/home/deploy/${APP_NAME}
# Production environment
export RAILS_ENV="production"
# This loads RVM into a shell session. Uncomment if you're using RVM system wide.
# [[ -s "/usr/local/lib/rvm" ]] && . "/usr/local/lib/rvm"
@elliotthilaire
elliotthilaire / fish-gotchas.md
Last active August 29, 2015 14:26
Bash things that don't work in Fish.

Command syntax

echo $(date +”%m_%d_%Y”)

Rewrite as

echo (date +”%m_%d_%Y”)

RVM

@elliotthilaire
elliotthilaire / pre-push
Last active October 12, 2018 10:07
A pre-push git hooking using the pronto gem
#!/bin/sh
# To reinstall this script in the same or another git repo run:
# curl -sSL https://gist.githubusercontent.com/elliotthilaire/cef91754bb296d67e776/raw/pre-push > .git/hooks/pre-push; chmod +x .git/hooks/pre-push
# check that pronto is installed
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;
#!/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;
@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')
}
@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 / 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 / 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 / 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