Skip to content

Instantly share code, notes, and snippets.

@jtimberman
jtimberman / chef-apply
Created October 15, 2013 15:03
the recipe as pasted into chef-shell or run with chef-apply to show the sequence of convergence
[2013-10-15T09:02:20-06:00] WARN: Happens before chef-sugar gem install
Recipe: (chef-apply cookbook)::(chef-apply recipe)
* chef_gem[chef-sugar] action install
- install version 1.0.0 of package chef-sugar
[2013-10-15T09:02:21-06:00] WARN: Happens after chef-sugar gem install
* package[sudo] action install
- install version 1.8.5p2-1+nmu1 of package sudo
* chef_gem[chef-sugar] action install (up to date)
* log[Happens during convergence] action write
* ruby_block[happens during convergence] action run[2013-10-15T09:02:22-06:00] WARN: nil
@nellshamrell
nellshamrell / gSchool Regex Resources
Last active March 25, 2016 21:49
Regex Resources for gSchool
Beginning Regex
Intro to Regular Expressions by Michael Fitzgeral
http://www.amazon.com/Introducing-Regular-Expressions-ebook/dp/B008K9OGDA/ref=sr_1_2?ie=UTF8&qid=1374171971&sr=8-2&keywords=Regular+Expressions
Using Regular Expressions in Ruby: Part 1 by Nell Shamrell
https://www.bluebox.net/insight/blog-article/using-regular-expressions-in-ruby-part-1-of-3
Intermediate Regex
@regularfry
regularfry / pmbi
Created October 10, 2013 01:35
Poor Man's Bundle Install
#!/usr/bin/env ruby
lockfile=ARGV.shift
sources=[]
gems=[]
File.foreach(lockfile) do |line|
case line
when /^ remote: (.*)$/
sources << $1
when /^ (\S+) \((.*)\)$/
@mlafeldt
mlafeldt / create-release.rb
Last active March 13, 2017 01:45
Accessing GitHub Releases API with Ruby -- http://developer.github.com/v3/repos/releases/
require "net/https"
require "json"
gh_token = ENV.fetch("GITHUB_TOKEN")
gh_user = ARGV.fetch(0)
gh_repo = ARGV.fetch(1)
release_name = ARGV.fetch(2)
release_desc = ARGV[3]
uri = URI("https://api.github.com")
@mitchellh
mitchellh / gist:6531113
Last active December 23, 2015 21:08
`go get` replacement that works around Go issue #5375 (go get doesn't work with private Bitbucket repositories)
#!/bin/bash
#
# Due to a bug in Go, you can't `go get` a private Bitbucket repository
# (issue #5375, linked below). This means you can't `go get ./...` ANY project
# that might depend on a private Bitbucket repository.
#
# This script works around it by detecting Bitbucket imports and using
# `git` directly to clone into it. This will not work if you use private
# Mercurial repositories on Bitbucket.
#
@dwayne
dwayne / ch1.md
Last active December 2, 2024 19:32
My notes from the book "Eloquent Ruby by Russ Olsen"

Chapter 1

Every programming community quickly converges on a style, an accepted set of idioms. Programming is all about communication and knowing those idioms are key to being a successful programmer in that community.

Ruby style of programming:

  • Code should be crystal clear, it should shout its intent
  • Good code is also concise

Ruby indentation convention:

##
# on each backend/non-routable cluster node
#
user_account "adminuser" do
ssh_keygen true
# other attributes perhaps?
end
# put the code in a ruby block so that it gets run in execution phase,
@jtimberman
jtimberman / for-example
Created August 21, 2013 14:22
Switching between organizations with Enterprise Chef with an environment variable.
% echo $ORGNAME
% knife config chef_server_url
chef_server_url: https://api.opscode.com/organizations/joshtest
% export ORGNAME=opstrain1
% knife config chef_server_url
chef_server_url: https://api.opscode.com/organizations/opstrain1
@nellshamrell
nellshamrell / Beneath the Surface: Embracing the True Power of Regular Expressions in Ruby
Last active December 3, 2017 16:35
Resources I consulted when preparing my presentation "Beneath the Surface: Embracing the True Power of Regular Expressions in Ruby"
All of these resources were extremely valuable as I researched regex, finite state machines, and regex in Ruby. Check them out, they're full of fantastic information!
Articles
"Exploring Ruby's Regular Expression Algorithm" by Pat Shaughnessy
http://patshaughnessy.net/2012/4/3/exploring-rubys-regular-expression-algorithm
"Finite State Machines and Regular Expressions" by Eli Bendersky
http://www.gamedev.net/page/resources/_/technical/general-programming/finite-state-machines-and-regular-expressions-r3176
"Regular Expression Matching Can Be Simple and Fast" by Russ Cox
@durran
durran / fields.rb
Created July 11, 2013 15:30
iterate models and fields.
Mongoid.models.each do |model|
model.fields.each do |name, field|
# name is the string name of the field, field is the Field object.
end
end