Skip to content

Instantly share code, notes, and snippets.

View kwilczynski's full-sized avatar

Krzysztof Wilczyński kwilczynski

  • Yokohama, Japan
  • 11:38 (UTC +09:00)
View GitHub Profile
@alexg0
alexg0 / Rakefile
Created April 16, 2010 18:02
for chef-repo - load and dump data bags
# ...
# append following lines
Dir[ File.join(File.dirname(__FILE__), 'tasks', '*.rake') ].sort.each do |f|
load f
end
@kwilczynski
kwilczynski / example.rb
Last active March 21, 2021 23:32
Get Twitter timeline in Ruby
module Twitter
def self.get_timeline(screen_name, query = {})
response = HTTParty.get(
"http://api.twitter.com/1/statuses/user_timeline.json?screen_name=#{screen_name}",
:query => query,
:format => :json
)
response.collect { |t| Hashie::Mash.new(t) }
end
end
@jacobian
jacobian / virtualenv-example.rb
Created October 5, 2010 21:36
My first Chef definition: create a virtualenv. Be nice.
# An example of the below
virtualenv "/home/dvcsmirrors/hg" do
owner "root"
group "dvcsmirrors"
mode 0775
packages "Mercurial" => "1.6.3",
"hgsubversion" => "1.1.2"
end
@jordansissel
jordansissel / Better Usage.md
Created December 20, 2010 12:07
Strip package scripts from .deb packages (postinst, postrm, preinst, prerm)

The best way to use this tool is to hook apt's use of dpkg to run it before doing any package installs.

In your apt.conf, put this:

DPkg::Pre-Install-Pkgs {"xargs -rL1 bash /path/to/stripdeb.sh 2>&1 | logger -t stripdeb"}

Then, a demo:

% sudo apt-get install mysql-server-5.1

def hash_to_params(hash)
hash.keys.inject("") do |qs, key|
qs << "&" unless qs.blank?
qs << if Array === hash[key]
k = CGI.escape(key.to_s)
hash[key].map { |value| "#{k}=" << CGI.escape(value.to_s) }.join("&")
else
CGI.escape(key.to_s) << "=" << CGI.escape(hash[key].to_s)
end
end
@shoban
shoban / mount-mon.c
Created February 21, 2011 19:53
Monitor for changes in mount points via /proc/mounts
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#define MOUNT_PROC "/proc/mounts"
@fnichol
fnichol / README.md
Created March 12, 2011 20:52
Download a cacert.pem for RailsInstaller

Why?

There is a long standing issue in Ruby where the net/http library by default does not check the validity of an SSL certificate during a TLS handshake. Rather than deal with the underlying problem (a missing certificate authority, a self-signed certificate, etc.) one tends to see bad hacks everywhere. This can lead to problems down the road.

From what I can see the OpenSSL library that Rails Installer delivers has no certificate authorities defined. So, let's go fetch some from the curl website. And since this is for ruby, why don't we download and install the file with a ruby script?

Installation

The Ruby Way! (Fun)

#!/bin/sh
#===============================================================================
#
# USAGE
# =====
#
# Get your X.509 Certificates and Private Key
# -------------------------------------------
@kwilczynski
kwilczynski / gist:931552
Created April 20, 2011 14:56
Puppet and The Magic of Define
# The following monstrosity ...
class test { }
define test::a($array) {
test::iterator { $name:
array => $array
}
}
@tnine
tnine / ebs_raid.rb
Created April 27, 2011 03:03
Ebs raid mounting. Links to this jira issue http://tickets.opscode.com/browse/CHEF-2275
include Opscode::Aws::Ec2
#Auto locates and attached ebs devices based on the data bag they reside in. The following test cases need to be performed
# Create multiple resources with new node: PASS
#
# Re-attach multiple resources after a reboot: PASS
#
# Create resources across 2 runs. First run creates first raid set, second run re-attaches then creates: PASS
#