Skip to content

Instantly share code, notes, and snippets.


Rob Bazinet rbazinet

View GitHub Profile
rbazinet / rss-to-s3.rb
Created May 30, 2020 14:12 — forked from peterc/rss-to-s3.rb
RSS to S3 Ruby Lambda Function
View rss-to-s3.rb
require 'json'
require 'aws-sdk-s3'
require 'open-uri'
# Ideally put these in environment variables
# but since this is just for us, who cares.
def do_newsletters
rbazinet / prefetch.js
Created February 6, 2020 03:31 — forked from hopsoft/prefetch.js
Turbolinks Prefetching
View prefetch.js
const hoverTime = 400
const fetchers = {}
const doc = document.implementation.createHTMLDocument('prefetch')
function fetchPage (url, success) {
const xhr = new XMLHttpRequest()'GET', url)
xhr.setRequestHeader('VND.PREFETCH', 'true')
xhr.onreadystatechange = () => {
if (xhr.readyState !== XMLHttpRequest.DONE) return
rbazinet / uploads_controller.rb
Created June 16, 2016 13:33 — forked from ifightcrime/uploads_controller.rb
Rails JSON file upload with carrierwave (from base64 string)
View uploads_controller.rb
class Api::UploadsController < ApiController
def create
@upload =
rbazinet / AllCraigslistLocations
Created June 12, 2016 00:47 — forked from jeffThompson/AllCraigslistLocations
A list of all active Craigslist locations. Format as a URL using "http://<location>".
View AllCraigslistLocations
rbazinet /
Created March 9, 2016 20:35 — forked from derwiki/
Ruby module that you can use in a `before_action` on sensitive controllers for which you'd like a usage audit trail

Adding an audit log to your Rails app

If you have any sort of administrative interface on your web site, you can easily imagine an intruder gaining access and mucking about. How do you know the extent of the damage? Adding an audit log to your app is one quick solution. An audit log should record a few things:

  • controller entry points with parameter values
  • permanent information about the user, like user_id
  • transient information about the user, like IP and user_agent

Using the Rails framework, this is as simple as adding a before_action to your admin controllers. Here’s a basic version that I’m using in production.

View filter_colors.hs
-- data structure for RGBA, RGB & CMYK colors
data Color = RGBA Float Float Float Float
| RGB Float Float Float
| CMYK Float Float Float Float
deriving (Eq, Ord, Show)
-- list of colors
colors = [ RGBA 0.1 0.1 0.5 0.2
, RGBA 1 1 0 0.9
, RGB 0.5 0.5 0
View gist:5824667
@implementation UITextView (RSExtras)
static BOOL stringCharacterIsAllowedAsPartOfLink(NSString *s) {
/*[s length] is assumed to be 0 or 1. s may be nil.
Totally not a strict check.*/
if (s == nil || [s length] < 1)
return NO;
View rails_log_stathat.rb
#!/usr/bin/env ruby
require 'net/http/persistent'
require 'uri'
require 'thread'
Parse a Rails log file and send metrics to stathat
export EMAIL=email
View Heroku tracking branch.txt
Assuming you have remote branch called heroku/master, start by creating a local tracking branch
called heroku.
> git checkout -b heroku -t heroku/master
This will checkout the last revision you deployed to Heroku.
Now tell git to push the heroku branch to heroku/master
> git config remote.heroku.push heroku:master
rbazinet /
Created November 29, 2012 16:01
Install ElasticSearch on Ubuntu 12.04
cd ~
sudo apt-get update
sudo apt-get install openjdk-7-jre -y
wget -O elasticsearch.tar.gz
tar -xf elasticsearch.tar.gz
rm elasticsearch.tar.gz
sudo mv elasticsearch-* elasticsearch
sudo mv elasticsearch /usr/local/share