Skip to content

Instantly share code, notes, and snippets.

View jmazzi's full-sized avatar

Justin Mazzi jmazzi

View GitHub Profile
@jmazzi
jmazzi / facebook-contact-info-summary.rb
Created March 30, 2018 20:09 — forked from dylanmckay/facebook-contact-info-summary.rb
A Ruby script for collecting phone record statistics from a Facebook user data dump
#! /usr/bin/env ruby
# NOTE: Requires Ruby 2.1 or greater.
# This script can be used to parse and dump the information from
# the 'html/contact_info.htm' file in a Facebook user data ZIP download.
#
# It prints all cell phone call + SMS message + MMS records, plus a summary of each.
#
# It also dumps all of the records into CSV files inside a 'CSV' folder, that is created
@jmazzi
jmazzi / import-cache.php
Created March 31, 2016 18:27 — forked from danielbachhuber/import-cache.php
During `wp import`, cache remote files locally for subsequent imports
<?php
/**
* Run with `wp --require=import-cache.php import ...
*/
WP_CLI::add_hook( 'after_wp_load', function(){
// Only intercept HTTP requests when the importer is running
if ( ! defined( 'WP_IMPORTING') || ! WP_IMPORTING ) {
return;

Displaying images in the terminal with tput and echo

output

Requires ImageMagick, easily available from your favorite package manager. Tested on Linux and OSX
convert image.png -resize 40 txt:-|sed -E 's/://;s/\( ? ?//;s/, ? ?/,/g;s/\)//;s/([0-9]+,[0-9]+,[0-9]+),[0-9]+/\1/g;s/255/254/g;/mage/d'|awk '{print $1,$2}'|sed -E 's/^0,[0-9]+ /print "echo;tput setaf "\;/;s/^[0-9]+,[0-9]+ /print "tput setaf ";/;s/(.+),(.+),(.+)/\1\/42.5*36+\2\/42.5*6+\3\/42.5+16/'|bc|sed 's/$/;echo -n "  ";/'|tr '\n' ' '|sed 's/^/tput rev;/;s/; /;/g;s/$/tput sgr0;echo/'|bash
require 'rubygems'
require 'mechanize'
FIRST_NAME = 'FIRST_NAME'
LAST_NAME = 'LAST_NAME'
PHONE = 'PHONE'
EMAIL = 'EMAIL@provider.com'
PARTY_SIZE = 2
SCHEDULE_RANGE = { :start_time => '19:00', :end_time => '20:30' }
sasha:~ brian$ echo $PATH
/Users/brian/.rbenv/bin:/Users/brian/.rbenv/shims:/Users/brian/bin:/Users/brian/clang+llvm-3.1/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/X11/bin:/opt/local/bin:/usr/local/bin:/opt/local/bin:/opt/local/lib/postgresql83/bin:/usr/local/mysql/bin:/usr/local/llvm/bin:/Users/brian/devel/android-1.1_r1/tools:/Users/brian/.cabal/bin:/Users/brian/.cljr/bin:/Users/brian/.rvm/bin
@jmazzi
jmazzi / chef.rb
Created July 27, 2012 03:26 — forked from gmcmillan/chef.rb
Simple Ruby class for manually querying the Chef REST API (using Net::HTTP instead of Chef's REST resources)
require 'base64'
require 'time'
require 'digest/sha1'
require 'openssl'
require 'net/https'
require 'json'
class Chef
attr_accessor :http, :path
@jmazzi
jmazzi / magic.rb
Created May 3, 2012 20:42 — forked from laserlemon/magic.rb
Patient Evaluation
class MagicProxy
@methods = []
def self.method_missing(method)
@methods << method
# Put magic here!
puts @methods.join('.')
self
end
end
@jmazzi
jmazzi / gist:2226172
Created March 28, 2012 13:28 — forked from svenfuchs/gist:2063855
Developing with dependent local gem repositories

When developing an application where you have split out shared functionality to multiple dependent gem repositories can get cumbersome when you

  • need to edit the Gemfile in order to swap local :path sources with :git or just plain Rubygems sources,
  • then forget to bundle update,
  • wonder why your git repository is dirty and it's just the modified Gemfile and Gemfile.lock,
  • accidentally commit the Gemfile.lock with local :path sources bundled etc. etc.

So what about this strategy:

A. Create a file .Gemfile.local containing:

require 'spec_helper'
class Foo
def bar; :foo_bar; end
end
describe Foo do
subject { Foo.new }
it do
@jmazzi
jmazzi / README.md
Created March 27, 2012 19:31 — forked from svenfuchs/README.md
minimal activerecord standalone migrations

In your Gemfile add:

group :development, :test do
  gem 'micro_migrations', :git => 'git@gist.github.com:33e9f92c229eb808a4fa.git'
end

You might want to add something like this to the Rakefile of apps that use a gem that uses micro_migrations:

ENV['SCHEMA'] = "#{Gem.loaded_specs['your-gem-name'].full_gem_path}/db/schema.rb"