Skip to content

Instantly share code, notes, and snippets.

View jeffsaracco's full-sized avatar

Jeff Saracco jeffsaracco

View GitHub Profile
@jeffsaracco
jeffsaracco / MongoFastUpsert.cs
Created October 17, 2011 00:09
Fast Inserts and Updates into MongoDB
private const string host = "mongodb://localhost/";
static void Main(string[] args)
{
MongoServer server = MongoServer.Create(host);
MongoDatabase test = server.GetDatabase("testDB");
List<int> list = Enumerable.Range(0, 100000).ToList();
@jeffsaracco
jeffsaracco / SqlTransactionRollback.sql
Created October 27, 2011 13:56
SQL Transaction w/rollback
BEGIN TRANSACTION
--SQL CODE HERE
if @@ERROR <> 0
BEGIN
ROLLBACK TRANSACTION
END
ELSE
BEGIN
@jeffsaracco
jeffsaracco / AspMVCBackButtonNoCache.cs
Created October 29, 2011 23:07
No Cache on ASP MVC Controller - to handle back button refresh
[OutputCache(NoStore = true, Duration = 0, VaryByParam = "None")]
public ActionResult Search(int param1, int param2)
{
//...action code
}
@jeffsaracco
jeffsaracco / wiki-scraper.rb
Created January 22, 2012 00:14 — forked from jdan/wiki-scraper.rb
(Nokogiri) Tests the idea that the first link on each wikipedia article will eventually lead to philosophy
#!/usr/bin/env ruby
# wiki-scraper.rb by Jordan Scales
#
# Tests the idea that the first link on each wikipedia article
# will eventually lead to philosophy
#
# Usage:
# ruby wiki-scraper.rb daft punk
@jeffsaracco
jeffsaracco / hack.sh
Created March 31, 2012 15:11 — forked from erikh/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@jeffsaracco
jeffsaracco / solution.rb
Created May 1, 2012 23:36 — forked from isa/gist:2571012
Convert in less than 30 lines
Question: Convert following into the latter data structure in less than 30 lines:
List:
A, B, C
A, C, E
E, F, D
D, A, J
E, D, J
List
@jeffsaracco
jeffsaracco / gist:4739403
Created February 8, 2013 14:39
Delete invalid remote git branches
#!/bin/bash
current_branch=$(git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')
if [ "$current_branch" != "master" ]; then
echo "WARNING: You are on branch $current_branch, NOT master."
fi
echo -e "Fetching merged branches...\n"
git remote update --prune
remote_branches=$(git branch -r --merged | grep -v '/master$' | grep -v "/$current_branch$")
@jeffsaracco
jeffsaracco / gist:5816289
Created June 19, 2013 17:45
Remove the effects of FriendlyId in ActiveAdmin

Even better you could create a before filter in the base Active Admin controller ActiveAdmin::ResourceController so that it is automatically inherited into all your Active Admin controllers.

First add the filter to the config/initializers/active_admin.rb setup:

ActiveAdmin.setup do |config|
  # ...
  config.before_filter :revert_friendly_id
end

The open up ActiveAdmin::ResourceController and add a revert_friendly_id method, E.g. by adding the following to the end of config/initializers/active_admin.rb:

@jeffsaracco
jeffsaracco / gist:6690215
Created September 24, 2013 19:43
Heroku database backup/restore/santize rake tasks
namespace :<MY APP NAMESPACE> do
namespace :db do
desc "Fetch the latest backup from heroku"
task :fetch => [:environment] do
app = ENV['app']
if app.blank?
puts "You must specify the heroku app name to get its database (use app=<appname>)"
else
url = `heroku pgbackups:url --app #{app}`
db_prefix = app.gsub('-','_')
@mixin background-image-retina($file, $type, $width, $height) {
background-image: url($file + '.' + $type);
@media (-webkit-min-device-pixel-ratio: 2), (-moz-min-device-pixel-ratio: 2) {
& {
background-image: url($file + '@2x.' + $type);
-webkit-background-size: $width $height;
}
}
}