Skip to content

Instantly share code, notes, and snippets.

View rbazinet's full-sized avatar

Rob Bazinet rbazinet

View GitHub Profile
@rbazinet
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.
BUCKET = "RETRACTED"
REGION = "RETRACTED"
def do_newsletters
@rbazinet
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()
xhr.open('GET', url)
xhr.setRequestHeader('VND.PREFETCH', 'true')
xhr.onreadystatechange = () => {
if (xhr.readyState !== XMLHttpRequest.DONE) return
@rbazinet
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 = Upload.new(upload_params)
ensure
clean_tempfile
end
private
@rbazinet
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>.craigslist.org".
auburn
bham
dothan
shoals
gadsden
huntsville
mobile
montgomery
tuscaloosa
anchorage
@rbazinet
rbazinet / README.md
Created March 9, 2016 20:35 — forked from derwiki/README.md
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.

-- 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
@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;
#!/usr/bin/env ruby
require 'net/http/persistent'
require 'uri'
require 'thread'
USAGE = <<EOS
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
rbazinet / es.sh
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 https://github.com/downloads/elasticsearch/elasticsearch/elasticsearch-0.19.0.tar.gz -O elasticsearch.tar.gz
tar -xf elasticsearch.tar.gz
rm elasticsearch.tar.gz
sudo mv elasticsearch-* elasticsearch
sudo mv elasticsearch /usr/local/share