Skip to content

Instantly share code, notes, and snippets.

@ktec
ktec / arel_cast_datetime_as_as.rb
Last active June 27, 2016 14:39
When you want to filter by date, but you've only got a datetime property, this will help you cast your datetime
# frozen_string_literal: true
class Things < ApplicationRecord
scope :filter_after_date, -> (date) {
where(created_at_as_date.gteq(date))
}
scope :filter_before_date, -> (date) {
where(created_at_as_date.lteq(date))
}
def self.created_at_as_date
Arel::Nodes::NamedFunction.new "DATE", [ arel_table[:created_at] ]
@squarism
squarism / iterm2.md
Last active July 18, 2024 12:46
An iTerm2 Cheatsheet

Tabs and Windows

Function Shortcut
New Tab + T
Close Tab or Window + W (same as many mac apps)
Go to Tab + Number Key (ie: ⌘2 is 2nd tab)
Go to Split Pane by Direction + Option + Arrow Key
Cycle iTerm Windows + backtick (true of all mac apps and works with desktops/mission control)
@justinweiss
justinweiss / filterable.rb
Last active January 11, 2024 07:28
Filterable
# Call scopes directly from your URL params:
#
# @products = Product.filter(params.slice(:status, :location, :starts_with))
module Filterable
extend ActiveSupport::Concern
module ClassMethods
# Call the class methods with names based on the keys in <tt>filtering_params</tt>
# with their associated values. For example, "{ status: 'delayed' }" would call
defmodule Example do
def main(args) do
args |> parse_args |> process
end
def parse_args(args) do
options = OptionParser.parse(args, switches: [help: :boolean],
aliases: [h: :help])
case options do
@martinos
martinos / local_io.rb
Created January 28, 2013 22:56
For testing io stdin and stdout interaction.
module SpecHelper
def local_io(in_str)
old_stdin, old_stdout = $stdin, $stdout
$stdin = StringIO.new(in_str)
$stdout = StringIO.new
yield
$stdout.string
ensure
$stdin, $stdout = old_stdin, old_stdout
end
@sdball
sdball / sandi_metz_rules_for_developers.md
Created January 18, 2013 18:47
Rules for good development from Sandi Metz

Sandi Metz’ rules for developers

  1. Your class can be no longer than a hundred lines of code.
  2. Your methods can be no longer than five lines of code
  3. You can pass no more than four parameters and you can't just make it one big hash.
  4. In your controller, you can only instantiate one object, to do whatever it is that needs to be done.
  5. Your view can only know about one instance variable.
  6. Your Rails view should only send messages to that object i.e., no Demeter violations.[ "thunder dome principal". Translated: one model in, one model out! ]
  7. Rules are meant to be broken if by breaking them you produce better code. [ ...where "better code" is validated by explaining why you want to break the rule to someone else. ]
@andrew
andrew / railscheck.rb
Last active December 10, 2015 20:59
Check your github account for out of date rails apps
## Rails Upgrade check
#
# Check your github repos for out of date rails apps
#
# usage: $ USERNAME=yourusername PASSWORD=yourpassword ruby railscheck.rb
# or
# usage: $ USERNAME=yourusername PASSWORD=yourpassword ORG=yourorgname ruby railscheck.rb
#
# n.b requires the octokit gem
@kytrinyx
kytrinyx / README.md
Created January 8, 2013 23:26
Take a snapshot of yourself on every commit.

Git Commit Snapshots

Snap a picture of yourself on every commit.

Probably Mac OS X only, I haven't looked into others.

$ brew install imagesnap
$ git config --global init.templatedir '~/.git_template'
$ chmod +x post-commit
class Form
include ActiveModel::Validations
extend ActiveModel::Naming
def self.wraps(model)
@wraps = model
end
def self.model_name
ActiveModel::Name.new(@wraps.to_s.classify.constantize)
@noahhendrix
noahhendrix / recipe.md
Created October 25, 2012 18:12
How to Sync RubyTapas with Podcasts
  1. Open the iTunes subscription (itpc://rubytapas.dpdcart.com/feed)
  2. Authenticate with your Ruby Tapas username and password
  3. Plug in your device and select it from the Devices menu
  4. Open the Podcasts tab
  5. Enable "Sync Podcasts"
  6. Ensure that RubyTapas is included in the sync list
  7. Press Apply
  8. Enable Wi-Fi syncing to get the episodes without plugging into your computer (optional)

Note: iTunes Syncing only works with the Podcasts app (https://itunes.apple.com/us/app/podcasts/id525463029?mt=8)