Skip to content

Instantly share code, notes, and snippets.

View MSch's full-sized avatar

Martin Schürrer MSch

View GitHub Profile
@MSch
MSch / cheat
Created July 15, 2010 14:19
Personal Vim cheatsheet
gc{motion} :: Toggle comments (for small comments within one line
the &filetype_inline style will be used, if
defined)
gcc :: Toggle comment for the current line
gC{motion} :: Comment region
\d :: Toggle NerdTREE
,w ,b :: CamelCaseMotion w b
We couldn’t find that file to show.
class ApplicationController < ActionController::Base
def session
@session_wrapper ||= SessionWrapper.new(request.session)
end
end
@MSch
MSch / todo.rb
Created November 15, 2010 22:28
def has_timer_for?(user)
Timer.where(:user_id => user.id, :todo_id => self.id).exists?
end
def timer_for(user)
Timer.find_or_create_by_todo_id_and_user_id(self.id, user.id)
end
#!/usr/bin/env ruby
require 'rubygems'
gems = Gem.source_index.search(Gem::Dependency.new(//, Gem::Requirement.default))
gems.each do |gem|
puts "gem '#{gem.name}', '#{gem.version.to_s}'"
end
module ActiveRecord
class Relation
def find_or_create
if self.exists?
self.first
else
self.create
end
end
end
Entry.find_in_batches(:conditions => "description_text IS NULL AND id > 354000", :batch_size => 1000) do |group|
puts group.first.id
ActiveRecord::Base.transaction do
group.each do |e|
e.refresh_description!
Entry.update_all({:description_text => e.description_text}, ['id = ?', e.id])
end
end
end
#!/usr/bin/env ruby
require File.expand_path('../../config/boot', __FILE__)
require 'zmq'
zmq = ZMQ::Context.new
socket = zmq.socket(ZMQ::PUSH)
socket.connect AppConfig[:email_zmq_socket]
#ARGF.binmode
#socket.send(ARGF.to_io.read)
@MSch
MSch / Gemfile
Created February 13, 2011 15:10
backtrace
# A sample Gemfile
source "http://rubygems.org"
# gem "rails"
gem 'devise', :git => 'https://github.com/plataformatec/devise.git'
DC.FirstRunView = DC.ContentView.design({
layout: { top: 43, left: 0 },
$inputs: function() {
return this.$('input');
}.cacheable(),
value: function() {
return this.get('$inputs')[0].value;
}.property('$inputs'),