Skip to content

Instantly share code, notes, and snippets.

View cwsaylor's full-sized avatar

Chris Saylor cwsaylor

View GitHub Profile
@cwsaylor
cwsaylor / 1_using_queries.js
Created June 23, 2017 23:00 — forked from katowulf/1_using_queries.js
Methods to search for user accounts by email address in Firebase
/***************************************************
* Simple and elegant, no code complexity
* Disadvantages: Requires warming all data into server memory (could take a long time for MBs of data or millions of records)
* (This disadvantage should go away as we add optimizations to the core product)
***************************************************/
var fb = firebase.database.ref();
/**
* @param {string} emailAddress
@cwsaylor
cwsaylor / mailchimp-firebase.js
Created June 23, 2017 04:14 — forked from eibrahim/mailchimp-firebase.js
A node worker for firebase to add a user to mailchimp
var mcapi = require('./node_modules/mailchimp-api/mailchimp');
var usersRef = db.ref('users');
var mc = new mcapi.Mailchimp('xxxxxxxxxx-api-key-us4');
usersRef.orderByChild('added_to_mailchimp').equalTo(null).on('child_added',function(snapshot){
var user = snapshot.val();
var key = snapshot.key;
if(user && user.email){
var listId = 'xxxx-list-id-xxxx';
var name = user.displayName || '';
module InterchangeHelper
def retina_image_tag(default_name, options={})
retina_name = default_name.gsub(%r{\.\w+$}, '@2x\0')
image_tag(default_name, options.merge('data-interchange' => "[#{asset_path(retina_name)}, (retina)]"))
end
end
module FlashHelper
DEFAULT_KEY_MATCHING = {
# Rails
:notice => :success,
:error => :alert,
# Foundation
:primary => :primary,
:secondary => :secondary,
:success => :success,
:warning => :warning,
module FlashHelper
ALERT_TYPES = {
success: :success,
notice: :success,
info: :info,
warning: :warning,
danger: :danger,
alert: :danger
}
ActiveAdmin.register_page "Mailers" do
sidebar :mailers do
ul do
li do
link_to "Password Reset", "/rails/mailers/devise_mailer/reset_password_instructions", target: "preview"
end
li do
link_to "Confirmation", "/rails/mailers/devise_mailer/confirmation_instructions", target: "preview"
end
li do
@cwsaylor
cwsaylor / README.md
Created March 3, 2016 17:43 — 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.

@cwsaylor
cwsaylor / gitcheats.txt
Created January 24, 2016 19:17 — forked from chrismccoy/gitcheats.txt
git cheats
# shortform git commands
alias g='git'
# cherry pick range of commits, starting from the tip of 'master', into 'preview' branch
git rev-list --reverse --topo-order master... | while read rev; do git checkout preview; git cherry-pick $rev || break; done
# create tracking branches for all remote branches
git branch -a | grep -v HEAD | perl -ne 'chomp($_); s|^\*?\s*||; if (m|(.+)/(.+)| && not $d{$2}) {print qq(git branch --track $2 $1/$2\n)} else {$d{$_}=1}' | csh -xfs;
# git reset newly added files
@cwsaylor
cwsaylor / index.html.slim
Last active August 29, 2015 14:23
Foundation Templates
.panel
.row
.small-12.columns
h1 Lorem Ipsum
p Nunc auctor bibendum eros. Maecenas porta accumsan mauris. Etiam enim enim, elementum sed, bibendum quis, rhoncus non, metus. Fusce neque dolor, adipiscing sed, consectetuer et, lacinia sit amet, quam. Suspendisse wisi quam, consectetuer in, blandit sed, suscipit eu, eros. Etiam ligula enim, tempor ut, blandit nec, mollis eu, lectus. Nam cursus. Vivamus iaculis. Aenean risus purus, pharetra in, blandit quis, gravida a, turpis. Donec nisl. Aenean eget mi. Fusce mattis est id diam. Phasellus faucibus interdum sapien. Duis quis nunc. Sed enim.
p = link_to "Get Started", new_user_registration_path
task showvars: :environment do
ActiveRecord::Base.connection.execute("show variables like '%character%'").each { |r| puts r }
end