Skip to content

Instantly share code, notes, and snippets.

Nick Larson ifightcrime

Block or report user

Report or block ifightcrime

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View wysihtml5-resize.js
this.editor = new wysihtml5.Editor("textarea");
this.editor.observe("load", function () {
var $iframe = $(this.composer.iframe);
var $body = $(this.composer.element);
'min-height': 0,
'line-height': '20px',
'overflow': 'hidden',
ifightcrime / gist:1251339
Created Sep 29, 2011
Delete all empty/false elements from hash recursively
View gist:1251339
# (v.respond_to?(:empty?) ? v.empty? : !v) is basically rails' .blank? in plain ruby
class Hash
def delete_blank
delete_if do |k, v|
(v.respond_to?(:empty?) ? v.empty? : !v) or v.instance_of?(Hash) && v.delete_blank.empty?
View blockquote.css
blockquote {
background: #f7f7f7;
font-family: Georgia;
padding: 14px 14px 12px 12px !important;
border: 1px solid #e7e7e7;
margin: 1em 3em;
text-align: right;
font-size: 10pt;
-webkit-border-radius: 5px;
ifightcrime / uploads_controller.rb
Created Jun 17, 2014
Rails JSON file upload with carrierwave (from base64 string)
View uploads_controller.rb
class Api::UploadsController < ApiController
def create
@upload =
git log --shortstat --pretty="%cE" | sed 's/\(.*\)@.*/\1/' | grep -v "^$" | awk 'BEGIN { line=""; } !/^ / { if (line=="" || !match(line, $0)) {line = $0 "," line }} /^ / { print line " # " $0; line=""}' | sort | sed -E 's/# //;s/ files? changed,//;s/([0-9]+) ([0-9]+ deletion)/\1 0 insertions\(+\), \2/;s/\(\+\)$/\(\+\), 0 deletions\(-\)/;s/insertions?\(\+\), //;s/ deletions?\(-\)//' | awk 'BEGIN {name=""; files=0; insertions=0; deletions=0;} {if ($1 != name && name != "") { print name ": " files " files changed, " insertions " insertions(+), " deletions " deletions(-), " insertions-deletions " net"; files=0; insertions=0; deletions=0; name=$1; } name=$1; files+=$2; insertions+=$3; deletions+=$4} END {print name ": " files " files changed, " insertions " insertions(+), " deletions " deletions(-), " insertions-deletions " net";}'
ifightcrime / gist:1712614
Created Jan 31, 2012
Cross browser iframe scrollWidth/scrollHeight and resize iframe to content
View gist:1712614
// Works for me in IE7+, Webkit, and FF
function resizeToContent(frame_id) {
var my_frame = document.getElementById(frame_id);
var content_width = my_frame.contentWindow.document.documentElement.scrollWidth;
var content_height = my_frame.contentWindow.document.documentElement.scrollHeight; = content_width + 'px'; = content_height + 'px';
ifightcrime /
Last active Oct 30, 2017
Simple set of bash scripts for uploading public keys to remote servers via GitHub usernames


A method for managing and giving team members access to remote servers without needing to pass around the master .pem key. Generates and sends authorized key files to a list of hosts based on a set of permissions.

Generates a new keys/*.txt file for each user defined in permissions.txt when one doesn't already exist. Gets the list by calling out to<user>.keys. After first fetching a set of keys, the list can be paired down if necessary before running

ifightcrime /
Last active Aug 10, 2017
Scrape a list of urls from a file
import io
import urllib.request
opener = urllib.request.FancyURLopener({})
pages_to_scrape = []
file = open("/Users/<user>/Downloads/random_slugs.txt", "r")
pages_to_scrape = file.readlines()
for url in pages_to_scrape:
ifightcrime / Dockerfile
Created Aug 6, 2017 — forked from yefim/Dockerfile
Build a Docker image, push it to AWS EC2 Container Registry, then deploy it to AWS Elastic Beanstalk
View Dockerfile
# Example Dockerfile
FROM hello-world
ifightcrime / log_exceptions.rb
Created May 12, 2017
Ruby logger helper method for friendly logging of exceptions with stack trace.
View log_exceptions.rb
class Logger
def exception(e, level=:error)
self.send level, "#{e.inspect} #{e.message}"
self.send level, " #{e.backtrace.first(25).join("\n ")}"
You can’t perform that action at this time.