Skip to content

Instantly share code, notes, and snippets.

@zachhale
zachhale / payflow_recurring.rb
Created March 10, 2010 20:45
Class extension for ActiveMerchant's PayPalGateway to add recurring billing code.
# http://blog.vuzit.com/2008/08/01/paypal-website-payments-pro-us-with-recurring-billing-and-activemerchant/
# The MIT License
#
# Copyright (c) 2008 Vuzit.com, Chris Cera, Tobias Luetke
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@pdswan
pdswan / patch_through_belongs_to.rb
Created November 12, 2010 15:39
swaps the foreign key and primary key to fix has_many and has_one through belongs_to in Rails 2.3.x
class ActiveRecord::Associations::ClassMethods::JoinDependency::JoinAssociation
# has_many and has_one through belongs_to are broken becuase the order of the primary key
# and foreign table key need to be reversed. this detects and fixes it.
def association_join_with_through_belongs_to_fix
join = association_join_without_through_belongs_to_fix
if [:has_many, :has_one].include?(reflection.macro) && reflection.options[:through] && source_reflection.macro == :belongs_to
connection = reflection.active_record.connection
parent_table_name = connection.quote_table_name(parent.aliased_table_name)
parent_key = connection.quote_column_name(parent.primary_key)
@mikhailov
mikhailov / installation.sh
Created November 23, 2010 15:18
nginx+passenger (real production config)
# NOTICE: to get Nginx+Unicorn best-practices configuration see the gist https://gist.github.com/3052776
$ cd /usr/src
$ wget http://nginx.org/download/nginx-1.2.1.tar.gz
$ tar xzvf ./nginx-1.2.1.tar.gz && rm -f ./nginx-1.2.1.tar.gz
$ wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.30.tar.gz
$ tar xzvf pcre-8.30.tar.gz && rm -f ./pcre-8.30.tar.gz
$ wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz
@matthewmccullough
matthewmccullough / gist:988077
Created May 24, 2011 03:02
Visualize Git Orphans via gitk and log
# Put this in your .gitconfig file under the alias section
orphank = !gitk --all `git reflog | cut -c1-7`&
# Then run it by typing 'git orphank' on the command line.
# A text version of the same is
orphanl = !git --pretty=oneline --abbrev-commit --graph --decorate `git reflog | cut -c1-7`
@we4tech
we4tech / _your_model.rb
Created June 20, 2012 03:49
Fix 1 error(s) on assignment of multiparameter attributes for dynamic column or encapsulated column accessor
# Put it on your model instance
def column_for_attribute(name)
# Put your accessor name, in my case :value
if :value == name.to_sym
self.class.columns_hash[self.field.value_column.to_s]
else
self.class.columns_hash[name.to_s]
end
end
@dariomncs
dariomncs / sphinx.conf
Created August 9, 2012 13:28
Sphinx configuration file using php
#!/usr/bin/php
#############################################################################
#
# S P H I N X C O N F I G U R A T I O N
#
#############################################################################
<?php
define('SPHINX_CONF_SOURCES_DIR', __DIR__ . DIRECTORY_SEPARATOR . "sources.d");
@jimothyGator
jimothyGator / README.md
Last active October 1, 2024 21:57
Nginx configuration for Mac OS X with Homebrew, using sites-enabled directory.
mkdir -p /usr/local/etc/nginx/sites-{enabled,available}
cd /usr/local/etc/nginx/sites-enabled
ln -s ../sites-available/default.conf
ln -s ../sites-available/default-ssl.conf

File locations:

  • nginx.conf to /usr/local/etc/nginx/
  • default.conf and default-ssl.conf to /usr/local/etc/nginx/sites-available
  • homebrew.mxcl.nginx.plist to /Library/LaunchDaemons/
@rschmitty
rschmitty / 660-init-deb.sh
Created June 29, 2013 17:11
Linode script to register nginx after passenger isntall http://library.linode.com/assets/660-init-deb.sh
#! /bin/sh
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon
@EtienneDepaulis
EtienneDepaulis / _form.html.erb
Last active February 4, 2023 13:24
Generating a grouped collection select with `simple_form`and a model using the `ancestry` gem
<%=
f.association :category_id, collection: Category.roots,
as: :grouped_select,
group_method: :children, group_label_method: :name,
label_method: :name
%>
@unak
unak / constraint.rb
Last active October 26, 2019 17:29
type constraint
class Module
class ConstraintError < TypeError; end
def where(meth, constraint)
m = Module.new do
define_method(meth) do |*args|
args.zip(constraint.keys.first) do |arg, t|
raise ConstraintError, "type #{t} is expected, but #{arg.inspect} is passed" unless arg.is_a?(t)
end
ret = super(*args)