Skip to content

Instantly share code, notes, and snippets.

@ChrisLusted
ChrisLusted / restart.sh
Created January 18, 2018 18:53 — forked from mattheworiordan/restart.sh
Heroku scheduled restarts
#!/bin/sh
# Set up the Heroku scheduler to run this command every hour. See example setup at https://goo.gl/nMCSH3
#
# Requires env vars to be set in Heroku with `heroku config:set`:
# - HEROKU_APP_NAME: this is just the app name in Heroku, i.e. `heroku apps` will list all apps you have access to
# - HEROKU_CLI_USER: Once Heroku CLI is authenticated (https://goo.gl/Qypr4x), check `cat .netrc` (or `_netrc` on Windows),
# look for `login` under `machine api.heroku.com`
# - HEROKU_CLI_TOKEN: As above, but use the `password` field
#
@ChrisLusted
ChrisLusted / SimpleStore.js
Created August 9, 2016 15:51 — forked from ksafranski/SimpleStore.js
Simple localStorage function with Cookie fallback for older browsers.
/**
* Simple localStorage with Cookie Fallback
* v.1.0.0
*
* USAGE:
* ----------------------------------------
* Set New / Modify:
* store('my_key', 'some_value');
*
* Retrieve:
@ChrisLusted
ChrisLusted / db.rake
Last active September 19, 2016 07:51 — forked from romansklenar/db.rake
Rake tasks to maintain Postgres tables
# lib/tasks/db.rake
namespace :db do
desc 'Maintains database by running command as ANALYZE, VACUUM and REINDEX'
task maintain: :environment do
verbose = ENV['VERBOSE'].present?
connection = ActiveRecord::Base.connection
puts "Maintaining database #{connection.current_database} ..."
connection.execute("VACUUM FULL #{'VERBOSE' if verbose}")
connection.execute("ANALYZE #{'VERBOSE' if verbose}")
require 'formula'
class Pngout < Formula
url 'http://static.jonof.id.au/dl/kenutils/pngout-20130221-darwin.tar.gz'
homepage 'http://www.jonof.id.au/kenutils'
md5 'ce71ba0648911931e4e822d83ebf128a6c4201c3'
version '20130221'
def install
prefix.install Dir['*']
@ChrisLusted
ChrisLusted / gist:9440912
Last active August 29, 2015 13:57
Foundation 5 block grids for bootstrap 3 sass
// Adapted from the awesome zurb foundation
// https://github.com/zurb/foundation/blob/v5.2.0/scss/foundation/components/_block-grid.scss
//
// Block Grid Mixins
//
// We use this to control the maximum number of block grid elements per row
$block-grid-elements: 12 !default;
# Example to initialize gridster and handle resizing
# Module grid settings
WIDGET_BASE_DIMENSIONS_X = WIDGET_DESKTOP_X = 140
WIDGET_BASE_DIMENSIONS_Y = 20
WIDGET_CONTAINER_SELECTOR = '.widget-view'
WIDGET_MOBILE_CUTOFF_WIDTH = 768
NUM_WIDGETS = 15
$ ->

An application I'm working on has two different types of Devise users, but I want both types of users to be able to use the same sign in form. Devise doesn't make this easy.

You could argue that I really should have a single user type with a role attribute, but the app is far enough along that I don't want to change that early design decision. It could be changed later if more pain points are discovered.

You could also argue that I shouldn't use Devise, but it's still the de facto authentication standard for Rails applications.

In this example, you can sign in as either a User or an AdminUser. This application only has two types of user, but this example could be extended to support any number of them more gracefully.

source 'https://rubygems.org'
gem 'rails', '3.2.9'
# Postgres Database
gem 'pg'
# Twitter API
gem 'twitter'
# ----------------
# file_concerns.rb
# ----------------
require 'uri'
module Models
module ComfortableMexicanSofa
module FileConcerns
extend ActiveSupport::Concern
<?php
// Set these dependant on your BB credentials
$username = 'username';
$password = 'password';
// Grab the data from BB's POST service and decode
$json = stripslashes($_POST['payload']);
$data = json_decode($json);