Skip to content

Instantly share code, notes, and snippets.

@gmcmillan
gmcmillan / chef.rb
Created July 26, 2012 22:25
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 ChefAPI
# Public: Gets/Sets the http object.
@gmcmillan
gmcmillan / parser.rb
Created April 4, 2012 17:59
my.cnf parser
def self.parse_config(file)
config = {}
File.open(file).each_line do |line|
line.strip!
# skip lines with comments or blank lines
next if /^\#/.match(line)
next if /^\s*$/.match(line)
# store which group in the config the line belongs to (e.g. [mysqld])
@gmcmillan
gmcmillan / ssl-domain-alias.php
Last active July 11, 2019 12:34
use a different domain for wp-admin, from this stack exchange post: http://wordpress.stackexchange.com/a/39210/81906
<?php
// this goes in wp-content/mu-plugins/ssl-domain-alias.php
/**
* Plugin Name: SSL Domain Alias
* Plugin URI: http://wordpress.stackexchange.com/questions/38902
* Description: Use a different domain for serving your website over SSL, set with <code>SSL_DOMAIN_ALIAS</code> in your <code>wp-config.php</code>.
* Author: TheDeadMedic
* Author URI: http://wordpress.stackexchange.com/users/1685/thedeadmedic
@gmcmillan
gmcmillan / download_all_chef_cookbooks.rb
Created February 13, 2013 01:21
Quick ruby script to download all cookbooks (all versions) from a Chef server.
#!/usr/bin/env ruby
cookbook_list = `knife cookbook list -a`.split("\n")
cookbook_list.each do |line|
line.strip!
line.match(/^([a-z0-9]+\-[a-z0-9-]+|\w+)\s+(\d\.\d\.\d|.+)$/)
name = $1
versions = $2
@gmcmillan
gmcmillan / purge-ban-domain-varnish.md
Created March 30, 2017 14:55 — forked from aderowbotham/purge-ban-domain-varnish.md
Purge (ban) an entire domain in Varnish Cache 3

How to purge ('ban') an entire domain in Varnish Cache 3

#####EDIT: NB Ban is technically different from Purge. Banned objects remain in memory but banning is faster than purging. Read the Varnish 3 documentation here and here.

Purge may be a more appropriate action for your use-case; although the examples in the gist below work, it's not necessarily the best way of doing this.


@gmcmillan
gmcmillan / safe_browsing.rb
Last active May 16, 2016 12:50
Ruby Class to Query Google Safe Browsing API in Batches
# Note: POST requests are limited to 500 domains each with the SB API, which is why this code splits it into batches
require 'net/https'
require 'open3'
class SafeBrowsing
attr_reader :opt
attr_accessor :results
FileBench Version 1.4.4
filebench> load webserver
98008: 3.236: Webserver Version 2.1 personality successfully loaded
98008: 3.236: Usage: set $dir=<dir>
98008: 3.236: set $filesize=<size> defaults to 16384
98008: 3.236: set $nfiles=<value> defaults to 1000
98008: 3.236: set $dirwidth=<value> defaults to 20
98008: 3.236: set $nthreads=<value> defaults to 100
98008: 3.236: set $iosize=<size> defaults to 1048576
98008: 3.236: run runtime (e.g. run 60)
@gmcmillan
gmcmillan / parse_ini.rb
Created January 21, 2013 17:58
Simple parser for my.cnf/ini files without needing an external library.
class Config
# The path to the config file as a String.
attr_reader :file
# Attributes used while config is parsed.
#
# Example:
# [mysqld] # group
# param = val # param, val

1. Install Xcode

2. Use XCode to install Command Line Utilities (GCC)

Open Xcode. Click the "Xcode" button in the top left of the screen near the Apple logo, then click "Preferences", then click "Downloads".

3. Install rbenv:

root@cvm01 [/var/cpanel]# /usr/local/cpanel/bin/fetch_cpconf_value access_log
/usr/local/cpanel/logs/access_log