Skip to content

Instantly share code, notes, and snippets.

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
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.
BUCKET = "RETRACTED"
REGION = "RETRACTED"
def do_newsletters
@rbazinet
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()
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 ifightcrime/uploads_controller.rb
Rails JSON file upload with carrierwave (from base64 string)
View uploads_controller.rb
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".
View AllCraigslistLocations
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
View README.md

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;
@rbazinet
rbazinet / tinyurl.rb
Created June 6, 2013 12:10
Simple Ruby class to shorten URLs using TinyURL.
View tinyurl.rb
class Tinyurl
include HTTParty
base_uri 'tinyurl.com'
def shorten(url)
self.class.get("/api-create.php?url=#{url}")
end
end
View rails_log_stathat.rb
#!/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
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