Skip to content

Instantly share code, notes, and snippets.

@clyfe
clyfe / as_r32_compat.rb
Created January 30, 2012 10:18
AS Rails 3.2 temp monkeypatch
# put in config/intializers/
module ActionView
class LookupContext
module ViewPaths
def find_all_templates(name, partial = false, locals = {})
prefixes.collect do |prefix|
view_paths.collect do |resolver|
temp_args = *args_for_lookup(name, [prefix], partial, locals, {})
temp_args[1] = temp_args[1][0]
@clyfe
clyfe / cancan.rb
Last active September 29, 2015 01:07
Monkey patch for CanCan 1.6.7, replaces MetaWhere with Squeel and more
# Setup
# =====
#
# Put this gist in Rails.root/config/initializers/cancan.rb
# Add Squeel to Gemfile, see https://github.com/ernie/squeel
#
# gem "squeel", "~> 0.9.3"
#
# Load Squeel hash and symbol extensions in squeel config initializer
#
@clyfe
clyfe / optimized_pdfkit.rb
Created November 1, 2011 11:06
An optimized version of pdfkit, with a slightly more involved interface
# Usage
#
# OptimizedPDFKit.new(html_tempfile).to_pdf(pdf_tempfile_path)
#
class OptimizedPDFKit < PDFKit
def initialize(url_file_or_html, options = {})
@source = Source.new(url_file_or_html)
@stylesheets = []
@clyfe
clyfe / _horizontal_subform_header.html.erb
Created October 1, 2011 17:18
diferentiate create/update subform columns
<thead>
<tr>
<%
readonly = (@record.readonly? or not @record.authorized_for?(:crud_type => :update))
crud_type = @record.new_record? ? :create : (readonly ? :read : :update)
config = active_scaffold_config_for(record.class)
columns = @record.new_record? ? config.create.columns : config.update.columns
columns.each :for => record.class, :crud_type => crud_type, :flatten => true do |column|
hidden = column_renders_as(column) == :hidden
next unless in_subform?(column, parent_record)
# Install Ruby 1.9.2 on CentOS
# https://github.com/imeyer/ruby-1.9.2-rpm
yum groupinstall "Development Tools"
yum install curl-devel openssl-devel httpd-devel apr-devel apr-util-devel libzlib-ruby zlib-devel
wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.2-p290.tar.gz
tar -zxvf ruby-1.9.2-p290.tar.gz
cd ruby-1.9.2-p290
./configure && make && make install
@clyfe
clyfe / jars.txt
Created September 15, 2011 14:15
My solr jars and schema (1.4)
apache-solr-cell-1.4.0.jar jempbox-0.2.0.jar
asm-3.1.jar log4j-1.2.14.jar
bcmail-jdk14-136.jar nekohtml-1.9.9.jar
bcprov-jdk14-136.jar ooxml-schemas-1.0.jar
commons-codec-1.3.jar pdfbox-0.7.3.jar
commons-compress-1.0.jar poi-3.5-beta6.jar
commons-io-1.4.jar poi-ooxml-3.5-beta6.jar
commons-lang-2.1.jar poi-scratchpad-3.5-beta6.jar
commons-logging-1.1.1.jar tika-core-0.4.jar
dom4j-1.6.1.jar tika-parsers-0.4.jar
@clyfe
clyfe / contracts.coffee
Created August 30, 2011 09:17
CoffeeScript contracts
guardArgs = (def, args) ->
i = 0
for arg, type of def
throw new Error("bad type of #{arg}") unless typeof args[i] == type
i++
typeEnsure = (def, f) -> ->
guardArgs(def, arguments)
f.apply @, arguments
1. Folosim ruby 1.9.2p190 de aici http://rubyinstaller.org/
Pentru NSIS fol comanda:
# https://github.com/oneclick/rubyinstaller/wiki/FAQ#wiki-silent_install
# very silent install to custom dir with file associations and PATH update
c:\>rubyinstaller.exe /verysilent /dir="d:\rubyABC" /tasks="assocfiles,modpath"
2. Pentru rulare ca serviciu folosim mongrel & mongrel_service (gemuri). Ai grija sa le pui ca dependinte pe production.
3. Inainte de a impacheta serverul de aplicatie (gislog) instalam toate dependintele si le vendorizam:
@clyfe
clyfe / nifty.py
Created July 20, 2011 20:47
Python nifty useful snippets I learned at pybucuresti and want to remember next time I need them
# stop the execution and open a debug console
import pdb; pdb.set_trace()
# inspect the object (what names it defines, as in methods)
dir(object)
# inspect the object more (the dictionary of attributes, as in properties)
dir(object.__dict__) # or something like that