Skip to content

Instantly share code, notes, and snippets.

@diragor
diragor / additional_date_calculations.rb
Last active September 1, 2023 18:21
Additional date/time calculations for Ruby on Rails ActiveSupport
# monkey-patching here, but extract and include however you like
module DateAndTime
module Calculations
# Returns true if the date/time is within the current week.
def current_week?
::Date.current.all_week.include?(to_date)
end
alias this_week? current_week?
@diragor
diragor / .slate
Created June 9, 2022 15:49
Slate config
# config for https://github.com/jigish/slate
bind a:cmd,alt,ctrl focus 'Basecamp 3'
bind b:cmd,alt,ctrl focus 'Safari'
#bind c:cmd,alt,ctrl focus 'Google Chrome'
bind c:cmd,alt,ctrl focus 'Firefox'
bind d:cmd,alt,ctrl focus 'Dash'
bind f:cmd,alt,ctrl focus 'Finder'
bind g:cmd,alt,ctrl focus 'GitHub Desktop'
bind h:cmd,alt,ctrl focus 'Atom'
@diragor
diragor / db_snap.rake
Last active March 27, 2024 02:50
Save and load named snapshots of your Rails development database. db_snap.rake file goes in lib/tasks, postgres_utils.rb goes in lib (or wherever you want, just fix the path in the rake code).
# usage:
# rake db:snap:save[name]
# rake db:snap:load[name]
# if no name is passed the current git branch name is used
require File.dirname(__FILE__) + '/../postgres_utils'
namespace :db do
namespace :snap do
desc 'Save a named snapshot of the development database'
@diragor
diragor / deploy.yml
Created August 31, 2018 15:21 — forked from caalberts/deploy.yml
Ansible Playbook to Deploy Rails to AWS
---
# Deploy rails app from localhost to remote servers
- name: Set up AWS infrastructure
hosts: localhost
connection: local
roles:
- setup_aws
- name: Package app
@diragor
diragor / keyboard_autolayout.swift
Created October 10, 2017 16:22
Responding to iOS keyboard show/hide/change with autolayout
// adapted from http://effortlesscode.com/auto-layout-keyboard-shown-hidden/
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillToggleNotification), name: .UIKeyboardWillShow, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillToggleNotification), name: .UIKeyboardWillChangeFrame, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillToggleNotification), name: .UIKeyboardWillHide, object: nil)
}
override func viewWillDisappear(_ animated: Bool) {
@diragor
diragor / montyhall.rb
Created March 15, 2017 21:13
Monty Hall problem in Ruby
# The Mythbusters episode on the Monty Hall problem inspired me to prove their conclusion in code.
# After writing this I looked around and didn't find anything much more concise. IMHO this
# is also more readable than most, as it's a straightforward representation of how you might
# perform a physical experiment.
ROUNDS = 100000
DOORS = [0,1,2]
choices = {
stick: 0,
###*
# SheetClip - Spreadsheet Clipboard Parser
# version 0.2
#
# This tiny library transforms JavaScript arrays to strings that are pasteable by LibreOffice, OpenOffice,
# Google Docs and Microsoft Excel.
#
# Copyright 2012, Marcin Warpechowski
# Licensed under the MIT license.
# http://github.com/warpech/sheetclip/
@diragor
diragor / db_snap.rake
Created December 12, 2014 18:24
This is a rake task and an optional git post-checkout hook to create and load sqlite development database snapshots in a Rails app. By default it assumes you want to name the snapshot after the current git branch, and the git hook will automatically load a snap that matches the name of the newly checked out branch. The rake file goes in lib/task…
# usage:
# rake db:snap:save[anyname]
# rake db:snap:load[somename]
# if no name is passed the current git branch name is used
namespace :db do
namespace :snap do
desc 'Save a named snapshot of the development sqlite database'
task :save, :name do |t, args|
name = args[:name] || `git rev-parse --abbrev-ref HEAD`.strip
@diragor
diragor / wootoff.rb
Last active August 29, 2017 22:30
Command line Woot-off tracker with Growl notification
# Woot-off tracker that does notifications for new items
# across all Woot sites.
#
# 2017-08-29
# Fixed main URL
#
# 2013-06-17
# Fixed for new site layout
# Notifications now via OS X Notification Center (see gem below)
# Clicking on notification launches site