Skip to content

Instantly share code, notes, and snippets.

@matschaffer
matschaffer / create_data_bag.rb
Created June 8, 2012 15:30
Creating local encrypted data bags
require 'rubygems'
require 'chef/encrypted_data_bag_item'
secret = Chef::EncryptedDataBagItem.load_secret('data_bag_key')
data = {"id" => "mysql", "root" => "some secret password"}
encrypted_data = Chef::EncryptedDataBagItem.encrypt_data_bag_item(data, secret)
FileUtils.mkpath('data_bags/passwords')
File.open('data_bags/passwords/mysql.json', 'w') do |f|
f.print encrypted_data.to_json
@swannodette
swannodette / gist:3217582
Created July 31, 2012 14:52
sudoku_compact.clj
;; based on core.logic 0.8-alpha2 or core.logic master branch
(ns sudoku
(:refer-clojure :exclude [==])
(:use clojure.core.logic))
(defn get-square [rows x y]
(for [x (range x (+ x 3))
y (range y (+ y 3))]
(get-in rows [x y])))
@troy
troy / oneline_detailed_logging.rb
Created August 10, 2012 02:13
One-line detailed logging for Rails 3 (ActiveSupport::Notifications) and later
# Outputs this at warn log level:
# 1.2.3.4 GET /path 200 OK BlahController#action HTML 938.2 (DB 11.8, View 719.7) {params} {optional params from flash[:log]}
#
# Save as config/initializers/oneline_detailed_logging.rb. Consider
# decreasing the log level from "info" to "warn" (in production.rb) so
# the one-line log message replaces the standard request logs.
# override process_action to add 2 things to the payload:
# - remote IP
@piscisaureus
piscisaureus / pr.md
Created August 13, 2012 16:12
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = [email protected]:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@alexmcpherson
alexmcpherson / scrape.js
Created September 17, 2012 00:52
Casper.js vimrc scraper
var casper = require("casper").create();
var url = "https://github.com/search?langOverride=VimL&language=&q=vimrc&repo=&type=Repositories&start_value=" + casper.cli.get(0);
var repoLinks = [];
var fileLinks = [];
function getRepoLinks() {
var links = [];
$("div.results .result h2 a").each(function(i,el){
links.push(el.href);
});
@gustin
gustin / sl_2012_notes.md
Created October 3, 2012 14:13 — forked from rbxbx/sl_2012_notes.md
Notes from strangeloop 2012 "The Higher Order Rubyist" talk

The Higher Order Rubyist

BUILT-INS

Obviously, when looking to program functionally in a given language, the first place one should look is within the language itself. Luckily, while not a Functional language (by any stretch of the word), Ruby has many facilities that enable it to act like one.

  • Enumerable
@elskwid
elskwid / Marked.sublime-build
Created November 19, 2012 21:38
Modify Markedapp build for sublime to include command palette entry
{
"cmd": ["open","-a","/Applications/Marked.app","$file"],
"selector": "text.html.markdown",
"variants": [
{
"cmd": ["open","-a","/Applications/Marked.app","$file"],
"name": "Open in Marked"
}
]
}
@aaronjensen
aaronjensen / edit_data_bag.rb
Created November 21, 2012 04:39
Edit encrypted data bags for use with chef-solo and knife-solo
#!/usr/bin/env ruby
Dir.chdir File.join(__FILE__, "../..")
unless ENV['EDITOR']
puts "No EDITOR found. Try:"
puts "export EDITOR=vim"
exit 1
end
unless ARGV.count == 2
@supernullset
supernullset / monsterAttack.rs
Created January 6, 2013 14:59
MonsterAttack
use core::rand::{Rng};
struct Monster {
name: ~str,
health: HealthPoints,
mut speed: int,
mut charisma: int,
mut max_attack: int,
position: Position
spawn = require('child_process').spawn
Q = require 'q'
# A capistrano command wrapper providing various helper methods for easier usage.
#
# Dependencies:
# child_process
# q: 0.9.x
class Capistrano
args = []