This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/forms/base_form.rb | |
class BaseForm | |
include ActiveModel::Validations | |
include ActiveModel::Conversion | |
extend ActiveModel::Naming | |
def initialize(attributes = {}) | |
attributes.each do |name, value| | |
send("#{name}=", value) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :db do | |
desc 'sync with prod database' | |
task :sync, :backup_id do |t, args| | |
dump_file = Rails.root.join('tmp', 'latest.dump') | |
db_configs = YAML.load_file(Rails.root.join('config', 'database.yml')) | |
db_config = db_configs[Rails.env] | |
commands = [ | |
"heroku pgbackups:capture --expire", | |
"curl -o #{dump_file} \`heroku pgbackups:url #{args[:backup_id]}\`", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env sh | |
# IMPORTANT: exclude the current branch (*), master and dev branch. Add any other patterns here | |
# and do a --dry-run if you're unsure | |
to_prune=$(git branch --merged dev | grep -v '\*\|master\|dev') | |
function show_help { | |
echo Usage: $(basename $0) | |
echo " -n [--dry-run] Print branches that would be removed" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* global angular */ | |
(function(module) { | |
'use strict'; | |
module.run(['$rootScope', '$state', 'Rails', | |
function($rootScope, $state, Rails) { | |
$rootScope.$on('$stateChangeError', function(event, toState, toParams, fromState, fromParams, error) { | |
switch(error.status) { | |
// or Rails.status.not_found.code (if using the version with descriptions) | |
case Rails.status.not_found.: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'optparse' | |
module CLI | |
COLORS = { | |
black: "\e[30;1m", | |
red: "\e[31m", | |
green: "\e[32m", | |
blue: "\e[34m", | |
white: "\e[37m", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# set the finddir lookup PATH | |
export DEFAULT_SEARCH_PATHS="~/Sites/apps:~/Sites/gems:~/Projects" | |
# use `finddir` to fuzzy lookup directories | |
function cds { | |
local search=$1; | |
local found=$(noglob finddir $search) | |
if [ $? -eq 0 ]; then | |
cd $found | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'optparse' | |
class Battery | |
DEFAULT_FORMAT = "P (S: R)" | |
def self.status | |
_, percent, status, remaining, _ = %x{pmset -g batt|grep InternalBattery}.split(/\t|;/).map(&:strip) | |
percent.gsub!(/%/, '') | |
remaining.gsub!(/[\(\)]/, '') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form name="form"> | |
<label> | |
Password | |
<input | |
type="password" | |
name="password" | |
ng-model="password" | |
required> | |
</label> | |
<small class="error" ng-show="form.password.$invalid"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e # works without this | |
set -x # debug | |
source "$HOME/.rvm/scripts/rvm" #so 'cd' will change gemset when dotfiles present | |
#setup | |
rm -rf ~/tmp/dir_with_gemfile | |
mkdir -p ~/tmp/dir_with_gemfile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
<title>Ohai</title> | |
<%= stylesheet_link_tag "application", media: "all" %> | |
<%= csrf_meta_tags %> | |
</head> | |
<body class="container"> |
OlderNewer