Skip to content

Instantly share code, notes, and snippets.

View cwsaylor's full-sized avatar

Chris Saylor cwsaylor

View GitHub Profile
@cwsaylor
cwsaylor / mongodb.rb
Created November 14, 2009 16:14 — forked from bkerley/mongodb.rb
db_config = YAML::load(File.read(RAILS_ROOT + "/config/mongodb.yml"))
if db_config[RAILS_ENV] && db_config[RAILS_ENV]['adapter'] == 'mongodb'
mongo = db_config[RAILS_ENV]
connection = Mongo::Connection.new(mongo['host'])
MongoMapper.connection = connection
MongoMapper.database = mongo['database']
if mongo['user'] && mongo['password']
MongoMapper.database.authenticate mongo['user'], mongo['password']
end
require 'rubygems'
require 'active_record'
ActiveRecord::Base.configurations['db1'] = {
:adapter => "mysql",
:host => "",
:database => "",
:username => "",
:password => ""
}
ActiveAdmin.register_page "Dashboard" do
menu :priority => 1, :label => proc{ I18n.t("active_admin.dashboard") }
content :title => proc{ I18n.t("active_admin.dashboard") } do
now = Time.now.getgm
columns do
column do
@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 / 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 / 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 || '';
@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