Skip to content

Instantly share code, notes, and snippets.

@scharfie
scharfie / boot-wordpress.php
Created May 21, 2014 16:31
boot-wordpress.php
if (!defined('WP_USE_THEMES')) {
define('WP_USE_THEMES', false);
require(dirname(__FILE__) . '/../../../../wp-config.php');
}
# constraint so sprockets /assets paths will not be caught by the assets controller
scope :constraints => lambda { |request| request[:controller] != 'assets' } do
match ':controller/:action.:format' => '#index'
match '/:controller(/:action(/:id))'
match ':controller/:action' => '#index'
match ':controller' => '#index'
end
# constraint so sprockets /assets paths will not be caught by assets/* URLs
scope :constraints => lambda { |request| !(request[:permalink] =~ /^assets\//) } do
[alias]
rb = "!f() { git push origin master:$1 && git checkout -t origin/$1; }; f"
class Thing
def self.build(data)
thing = new(data)
thing.valid? ? thing : nil
end
def initialize(data)
@url = data[:url]
end
#
# Recurring Job using Delayed::Job
#
# Setup Your job the "plain-old" DJ (perform) way, include this module
# and Your handler will re-schedule itself every time it succeeds.
#
# Sample :
#
# class MyJob
# include Delayed::ScheduledJob
@scharfie
scharfie / en.rb
Last active December 15, 2015 07:10
i18n lambda + using view helpers in error messages
# config/locales/en.rb
{
:en => {
:activerecord => {
:errors => {
:models => {
:bid => {
:price_too_low => lambda { |errors,attributes|
helpers = ActionController::Base.helpers
currency = attributes[:price] || 0
var marshalledForm = new MarshalledForm('#starting_xi_form');
marshalledForm.add(':input', new MarshalledForm.Serializers.FormField());
marshalledForm.add('img.player_image', new MarshalledForm.Serializers.Attribute("src"));
marshalledForm.add('span.name', new MarshalledForm.Serializers.HTML());
@scharfie
scharfie / wol.rb
Created July 18, 2012 16:03 — forked from zunda/wol.rb
A ruby script which sends out a magic packet to wake up your PC
#!/usr/bin/ruby
# wol.rb: sends out a magic packet to wake up your PC
#
# Copyright (c) 2004 zunda <zunda at freeshell.org>
# Modified by scharfie <scharfie at gmail dot com>
#
# This program is free software. You can re-distribute and/or
# modify this program under the same terms of ruby itself ---
# Ruby Distribution License or GNU General Public License.
#
pyRenamer - rename files
DragonDisk - S3 gui
Pithos - Pandora music player GUI
Shutter - screen capture
ClipIt - clipboard history
Pinta - image editor (sort of a lightweight PS)
@scharfie
scharfie / copy-s3-bucket.rb
Created March 8, 2012 14:15 — forked from zefer/copy-s3-bucket.rb
Copy contents of an S3 bucket to a another bucket using an EC2 instance and a simple Ruby script. Useful for transferring large amounts of data and will work across geographic regions.
require 'rubygems'
require 'right_aws'
require 'yaml'
filename = ENV['FILE'].to_s
source = ENV['FROM'].to_s
destination = ENV['TO'].to_s
dry_run = true
puts "Please provide filename of s3 configuration" and exit(1) if filename == ""