Skip to content

Instantly share code, notes, and snippets.

View mikz's full-sized avatar

Michal Cichra mikz

View GitHub Profile
class Reservation::Group < ActiveRecord::Base
set_table_name "reservation_groups"
has_many :reservations, :foreign_key => "group_id"
has_many :reservation_views, :order => "start DESC, duration ASC", :foreign_key => "group_id", :class_name => "Reservation::View"
attr_accessor :tmpid
validates_presence_of :name
default_scope :order => "LOWER(name) ASC"
end
@mikz
mikz / gist:574015
Created September 10, 2010 17:14
def quoted_date(value)
if value.acts_like?(:time) && value.respond_to?(:usec)
begin
"#{value.getutc.to_s(:db)}.#{sprintf("%06d", value.usec)} #{value.formatted_offset}"
rescue
"#{super}.#{sprintf("%06d", value.usec)}"
end
else
super
@mikz
mikz / format.js
Created September 24, 2010 12:49
(function(){
var Format = {
defaults: {
precision: 3,
delimiter: ',',
separator: '&nbsp;',
fixed_length: false,
fixed_delimiter: " ",
precision_unit: null,
currency: "Kč"
@mikz
mikz / Twister.rb
Created December 14, 2010 11:37
Randomly selects body parts and colors and then speaks instructions. Controller by voice. Depends on MacRuby.
#/usr/bin/env ruby
framework "AppKit"
app = NSApplication.sharedApplication
class TwisterDelegate
SIDES = %w{left right}
BODY_PARTS = %w{foot hand}
COLORS = %w{red green blue yellow}
Private Sub GeneratePasswords(sheetName As String, count As Integer)
For i = 1 To count
Sheets(sheetName).Cells(i, 2).Value = GeneratePassword
Next i
End Sub
Public Function GeneratePassword() As String
Dim lowercase, decimals, special As String
Imports Calculator.CalculatorModel
Public Class Calculator
Dim WithEvents model As CalculatorModel
Private Sub MemoryController(ByVal sender As System.Windows.Forms.Button, ByVal e As System.EventArgs) Handles MemCBtn.Click, MemMBtn.Click, MemPBtn.Click, MemRBtn.Click, MemSBtn.Click
Try
#!/usr/bin/env macruby
# encoding: utf-8
CALENDARS = ['Michal Cichra', 'Calendar'] # Set names of calendars to show
before = 3 # days to show before today
after = 10 # days to show after today
today = 'dnes'
@mikz
mikz / factory_girl.rb
Created September 5, 2011 21:39
factory_girl singleton helper
require 'factory_girl/step_definitions'
def FactorySingleton(*args)
FactorySingleton.find_or_self *args
end
module FactorySingleton
def find_or_self object, attribute = nil
# FIXME: instead of this probably could check validation reflection for unique attributes
attribute ||= case object
@mikz
mikz / gist:1337933
Created November 3, 2011 22:07
Rate current song in iTunes - Alfred Extension - requires macruby
read -s -r -d '' SCRIPT <<"EOF"
framework 'ScriptingBridge'
rating = ARGV.pop
itunes = SBApplication.applicationWithBundleIdentifier("com.apple.itunes")
track = itunes.currentTrack
track.rating = rating.to_f*20
puts "#{track.artist} - #{track.name} rated #{rating} stars"
EOF
@mikz
mikz / currency_converter.coffee
Created November 5, 2011 23:04
Depends on money.js, nodejs, coffeescript and request
request = require('request')
money = require('money')
fs = require('fs')
arguments = process.argv.splice(2)
amount = arguments.shift()
try
loop
base = arguments.shift()