Skip to content

Instantly share code, notes, and snippets.

View danielribeiro's full-sized avatar

Daniel Ribeiro danielribeiro

View GitHub Profile
require 'json'
require 'ostruct'
require 'pp'
str = { woo: [ 1, 2, 3], yay: { foo: true, bar: ["42", 2, {}] } }.to_json
pp JSON.parse(str, object_class: OpenStruct).yay.bar
man() {
env \
LESS_TERMCAP_mb=$(printf "\e[1;31m") \
LESS_TERMCAP_md=$(printf "\e[1;31m") \
LESS_TERMCAP_me=$(printf "\e[0m") \
LESS_TERMCAP_se=$(printf "\e[0m") \
LESS_TERMCAP_so=$(printf "\e[1;44;33m") \
LESS_TERMCAP_ue=$(printf "\e[0m") \
LESS_TERMCAP_us=$(printf "\e[1;32m") \
man "$@"
require 'openssl'
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
@danielribeiro
danielribeiro / optparsing.rb
Last active May 31, 2016 06:04
optparsing.rb
#!/usr/bin/env ruby
require 'optparse'
require 'pp'
options = {}
parser = OptionParser.new do |opts|
opts.banner = "Usage: example.rb [options]"
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
options[:verbose] = v
@danielribeiro
danielribeiro / timeout.rb
Created April 4, 2016 23:23 — forked from lpar/timeout.rb
Run a shell command in a separate thread, terminate it after a time limit, return its output
# Runs a specified shell command in a separate thread.
# If it exceeds the given timeout in seconds, kills it.
# Returns any output produced by the command (stdout or stderr) as a String.
# Uses Kernel.select to wait up to the tick length (in seconds) between
# checks on the command's status
#
# If you've got a cleaner way of doing this, I'd be interested to see it.
# If you think you can do it with Ruby's Timeout module, think again.
def run_with_timeout(command, timeout, tick)
output = ''
@danielribeiro
danielribeiro / gist:f4dcaf4b56a5621450ac
Created March 21, 2016 22:43 — forked from sonsongithub/gist:2868639
Parse Xcode project file, project.pbxproj, in Ruby.
json = JSON.parse(`plutil -convert json -o - "#{filename}"`)
@danielribeiro
danielribeiro / mynewprod.d
Created November 6, 2015 00:35
unlimited newprod.d
#!/usr/sbin/dtrace -s
/*
* newproc.d - snoop new processes as they are executed. DTrace OneLiner.
*
* This is a DTrace OneLiner from the DTraceToolkit.
*
* 15-May-2005 Brendan Gregg Created this.
*/
/*
#!/bin/sh
#
# Adam Sharp
# Aug 21, 2013
#
# Usage: Add it to your PATH and `git remove-submodule path/to/submodule`.
#
# Does the inverse of `git submodule add`:
# 1) `deinit` the submodule
# 2) Remove the submodule from the index and working directory
@danielribeiro
danielribeiro / Rakefile
Last active August 27, 2015 08:15 — forked from alloy/Rakefile
A Rakefile that standardises program env installation and guides the user, as opposed to crashing with Ruby exceptions such as `LoadError`. The only case where this will *never* work reliably is if you use the `rubygems-bundler` (NOEXEC) plugin, which introduces chicken-and-egg problems.
# Do *not* load any libs here that are *not* part of Ruby’s standard-lib. Ever.
desc "Install all dependencies"
task :bootstrap do
if system('which bundle')
sh "bundle install"
sh "git submodule update --init"
# etc
else
$stderr.puts "\033[0;31m[!] Please install the bundler gem manually: $ [sudo] gem install bundler\e[0m"