Skip to content

Instantly share code, notes, and snippets.

View andywenk's full-sized avatar

Andreas Wenk andywenk

View GitHub Profile
@andywenk
andywenk / gist:3491760
Created August 27, 2012 19:55
orders complete
show do | order |
attributes_table do
items = OrderItem.where("order_id=?", order.id)
row :id
row :user_id do
user = User.find(order.user_id)
link_to("#{user.first_name} #{user.last_name}", admin_user_path(order.user_id))
end
row "ORDER ITEMS" do
@andywenk
andywenk / gist:3569769
Created September 1, 2012 11:01
elasticsearch start/stop script
#! /bin/sh
### BEGIN INIT INFO
# Provides: elasticsearch
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Starts elasticsearch
# Description: Starts elasticsearch using start-stop-daemon
### END INIT INFO
@andywenk
andywenk / printer.rb
Created September 18, 2012 21:58
difference between size and length when using AR and DISTINCT
class Printer < ActiveRecord::Base
belongs_to :manufacturer
has_many :printer_cartridges
has_many :cartridges, :through => :printer_cartridges
attr_accessible :name, :id, :manufacturer_id
attr_accessor :manufacturer, :group, :page, :pages, :per_page, :total
def initialize(args = {})
super
@andywenk
andywenk / import-example.rb
Created November 4, 2012 21:34
csv-import-example
# This is a basic example how to create an import from csv data. This could
# be called in a rake task:
namespace :db do
namespace :import do
desc "Import customer of old shop from csv"
task :customer => :environment do
csv_file = 'db/customer_data.csv'
importer = Import::ImportCustomer.new(IO.read(csv_file))
importer.import
@andywenk
andywenk / div_composing-example.html
Created November 11, 2012 15:30
div_composing-example
<!doctype html>
<html>
<head>
<title>div composing example</title>
<style type="text/css">
html, body {
margin:0;
padding:0;
background-color: #ddd;
}
@andywenk
andywenk / knockout-working-with-lists-and-collections.js
Created November 23, 2012 11:07
examples from knockout.js tutorial working with lists and collections
// HTML code
//<h2>Your seat reservations (<span data-bind="text: seats().length"></span>)</h2>
//<table>
// <thead><tr>
// <th>Passenger name</th><th>Meal</th><th>Surcharge</th><th></th>
// </tr></thead>
// <!-- Todo: Generate table body -->
// <tbody data-bind="foreach: seats">
@andywenk
andywenk / alias.rb
Created February 26, 2013 13:03
Sample code to show alias and alias_method is working in Ruby. The related blogpost can be found here: http://goo.gl/4dhVy
#!/usr/bin/env ruby
class NoAlias
def nice_method
puts 'I am the nice method'
end
def even_nicer_method
puts 'I am the even nicer method'
end
class Alias
def even_nicer_method
puts 'I am the total perfect method'
end
alias :nice_method :even_nicer_method
end
puts 'Example with the usage of alias'
Alias.new.nice_method
class AliasMethod
def even_nicer_method
puts 'AliasMethod::even_nicer_method called'
end
alias_method :nice_method, :even_nicer_method
end
puts 'Example with usage of alias_method'
AliasMethod.new.nice_method
class Mother
def say_name
puts 'I am the Mother'
end
alias :name :say_name
#alias_method :name, :say_name
end
class Child < Mother