Skip to content

Instantly share code, notes, and snippets.

View richardkmichael's full-sized avatar

Richard Michael richardkmichael

  • 01:41 (UTC -08:00)
View GitHub Profile
@rokotyan
rokotyan / .block
Last active December 12, 2023 13:07
Export SVG D3 visualization to PNG or JPEG
license: mit
@tenderlove
tenderlove / mt_complete.rb
Last active December 11, 2020 19:56
tab completion for minitest tests
#!/usr/bin/env ruby --disable-gems
# Tab completion for minitest tests.
#
# INSTALLATION:
#
# 1. Put this file in a directory in your $PATH. Make sure it's executable
# 2. Run this:
#
# $ complete -o bashdefault -f -C /path/to/this/file.rb ruby
@solnic
solnic / active-rom.rb
Created January 29, 2015 21:06
ActiveROM ;)
require 'rom-sql'
require 'virtus'
module ActiveRecord
class Base
def self.inherited(klass)
rel_class = Class.new(ROM::Relation[:sql]) {
base_name Inflecto.tableize(klass.name).to_sym
}
dataset = repository.dataset(rel_class.base_name)
@marcelosomers
marcelosomers / git-php-webhook.php
Last active October 17, 2024 17:17
A basic webhook for deploying updates to repos on Github to your local server
<?php
/**
* This script is for easily deploying updates to Github repos to your local server. It will automatically git clone or
* git pull in your repo directory every time an update is pushed to your $BRANCH (configured below).
*
* Read more about how to use this script at http://behindcompanies.com/2014/01/a-simple-script-for-deploying-code-with-githubs-webhooks/
*
* INSTRUCTIONS:
* 1. Edit the variables below
* 2. Upload this script to your server somewhere it can be publicly accessed
@GriffithStudio
GriffithStudio / .readme.md
Created August 27, 2012 18:10
Promise Pegasus RAID Scripts

Promise Pegasus RAID Scripts

Background

The Pegasus R6 is an incredible storage device, but it lacks the reasonable ability to send email alerts. Following Angel's blog post here here, I modified the scripts so they could run from launchd. Firstly, I had to use the PTY public class in order to communicate with the promiseutil command. This is because promiseutil is an interactive program that assumes that it is a run through TTY. Secondly, I added in system logging in case the email feature fails for some reason.

launchd

While these scripts work fine from the terminal's cli, running them through launchd can cause you problems because of the spawning subprocesses (mail and promiseutil). In order to get those to work properly, you must also use the AbandonProcessGroup directive. Below is the example:

require 'minitest/unit'
require 'drb'
require 'rinda/tuplespace'
module MiniTest
class ParallelRunner < MiniTest::Unit
URI = 'druby://127.0.0.1:12345'
def _run_suites suites, type
hash = Hash[suites.map { |s| [s.name, s] }]
@ryanlecompte
ryanlecompte / gist:1619490
Created January 16, 2012 06:59
Experimenting with forking and unix sockets in Ruby
require 'base64'
require 'socket'
require 'fileutils'
# UnixSocketForker is an experiment of inter-process communication using
# plain unix sockets to communicate between forked processes and the
# parent process. This can also be done via IO.pipe. In this experiment,
# the jobs are simply random arrays whose sums are calculated in the forked
# worker processes.
class UnixSocketForker
@dansimau
dansimau / pgprepmgr.sh
Created January 9, 2012 10:57
Wrapper for pgpools' pcp tools to help you manage your pgpool setup and postgresql cluster. See usage in the comment below.
#!/bin/bash
#
# pgpool-II replication manager
#
# Interfaces with pgpool's pcp command-line tools to provide access to common functions for managing
# load-balancing and failover.
#
# [email protected]
# 2011-08-28
@bigfive
bigfive / gist:1399762
Created November 28, 2011 09:33
Ruby on Rails. Module to handle 'quantity' attributes by overriding the << and delete methods of the has_many association
class Package < ActiveRecord::Base
has_many :products, :through => :packagings, extend => QuantityAssociation
# ... do stuff
end
module QuantityAssociation
def include_duplicates
@netj
netj / memusg
Last active November 5, 2024 15:18
memusg -- Measure memory usage of processes
#!/usr/bin/env bash
# memusg -- Measure memory usage of processes
# Usage: memusg COMMAND [ARGS]...
#
# Author: Jaeho Shin <[email protected]>
# Created: 2010-08-16
############################################################################
# Copyright 2010 Jaeho Shin. #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); #