Skip to content

Instantly share code, notes, and snippets.

View rbazinet's full-sized avatar

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
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
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 longlostnick/uploads_controller.rb
Rails JSON file upload with carrierwave (from base64 string)
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>".
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.

@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;
rbazinet / tinyurl.rb
Created June 6, 2013 12:10
Simple Ruby class to shorten URLs using TinyURL.
class Tinyurl
include HTTParty
base_uri ''
def shorten(url)
#!/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
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