Skip to content

Instantly share code, notes, and snippets.

@mjc
mjc / DD32s-combine-plugin.php
Created Dec 5, 2008
WIP: Combine Javascript and CSS in wordpress
View DD32s-combine-plugin.php
<?php
/*
Plugin Name: The Combiner
Plugin URI: http://dd32.id.au/wordpress-plugins/?plugin=combine-css-js
Description: Combine CSS & JS into one large monolithic file
Author: DD32
Version: 1.0
Author URI: http://dd32.id.au/
*/
@mjc
mjc / optimizeimages.sh
Last active Oct 21, 2019 — forked from mstroeck/optimizeimages.sh
Shell script to recursively optimize all image in the current directory. WARNING: THIS OVERWRITES YOUR ORIGINALS AND REMOVES METADATA!
View optimizeimages.sh
#!/bin/sh
set -o errexit
# @TODO detect fd and fallback to find
pngs=$(fd -e png .)
jpgs=$(fd -e jpg .)
#pngs=$(find . -iname "*.png")
#jpgs=$(find . -iname "*.jpg")
optimize_a_png() {
@mjc
mjc / fizz_buzz_test.exs
Last active Jul 13, 2019
test for fizzbuzz
View fizz_buzz_test.exs
defmodule FizzBuzzTest do
use ExUnit.Case
# to run tests: mix test
# to get an irb equivalent with your code loaded in it: iex -S mix
# to get a pry in your code: `require IEx;IEx.pry()`
# Phase 1: make the test pass.
# Phase 2: implement the fizz/buzz check as a pattern match
# Phase 3: move the pattern match into multiple function clauses.
@mjc
mjc / iso8601_to_datetime.sql
Created Nov 28, 2012
MySQL function to convert from ISO8601 to DATETIME
View iso8601_to_datetime.sql
delimiter $$
CREATE FUNCTION ISO8601_DATETIME(iso varchar(26))
RETURNS DATETIME
DETERMINISTIC
BEGIN
RETURN CONVERT_TZ(
STR_TO_DATE(
CONCAT(SUBSTRING(iso, 1, 10),
' ',
SUBSTRING(iso, 12, 8)),
View README.md

Setup

Add the following gems to your Gemfile:

gem 'activeresource'
gem 'newrelic_api'

Update your bundle:

View gist:485383
<?php
/*
Plugin Name: Get OSCommerce Cart Contents from session
Plugin URI: http://325i.org/osc
Description: allows you to retrieve the cart contents from your OSCommerce install. Requires that your cookie path would include both OSC and wordpress. Works with OSCommerce 2.2RC2.
Author: Michael J. Cohen <mjc@kernel.org>
Version: 1
Author URI: http://325i.org
*/
@mjc
mjc / config.ru
Last active Jan 3, 2016 — forked from ngs/config.ru
config.ru for running CakePHP apps under Pow. Includes an app/webroot rewrite and some other things from the rack-legacy example.
View config.ru
require 'rack'
require 'rack-legacy'
require 'rack-rewrite'
webroot = File.join(Dir.getwd,'app','webroot')
use Rack::Rewrite do
rewrite %r{/(.*)}, lambda { |match, rack_env|
File.exists?(File.join(webroot,match[1])) ? File.join('app','webroot',match[1]) : '/app/webroot/index.php/%s' % match[1]
}
@mjc
mjc / activemerchant.gemspec.diff
Created Jul 30, 2013
trying to add fake extension to activemerchant to allow conditionally requiring nokogiri based on ruby version at gem install time
View activemerchant.gemspec.diff
index 652e40c..233d9df 100644
--- a/activemerchant.gemspec
+++ b/activemerchant.gemspec
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
s.homepage = 'http://activemerchant.org/'
s.rubyforge_project = 'activemerchant'
- s.files = Dir['CHANGELOG', 'README.md', 'MIT-LICENSE', 'CONTRIBUTORS', 'gem-public_cert.pem', 'lib/**/*', 'vendor/**/*']
- s.require_path = 'lib'
+ s.files = Dir['CHANGELOG', 'README.md', 'MIT-LICENSE', 'CONTRIBUTORS', 'gem-public_cert.pem', 'lib/**/*', 'vendor/**/*', 'ext/nokogiri_conf.rb']
@mjc
mjc / gist:6029781
Created Jul 18, 2013
rbx error differences
View gist:6029781
class Moo
def self.moo
a = 50a
end
end
# require './moo.rb' in pry
# rbx:
# SyntaxError: /usr/local/rvm/rubies/rbx-head/runtime/melbourne.rbc:81: expecting keyword_end
# from /usr/local/rvm/rubies/rbx-head/runtime/melbourne.rbc:81:in `syntax_error'
@mjc
mjc / gist:6029403
Created Jul 18, 2013
fix for HTTParty in rbx 2.0 mode
View gist:6029403
diff --git a/lib/20/net/http.rb b/lib/20/net/http.rb
index fd8c802..2266617 100644
--- a/lib/20/net/http.rb
+++ b/lib/20/net/http.rb
@@ -321,7 +321,7 @@ module Net #:nodoc:
# HTTPResetContent:: 205
# HTTPPartialContent:: 206
# HTTPRedirection:: 3xx
- # HTTPMultipleChoice:: 300
+ # HTTPMultipleChoices:: 300