Skip to content

Instantly share code, notes, and snippets.

@jbmyid
jbmyid / calendar_helper.rb
Last active September 12, 2017 20:33
Display dynamic calendar in view
module CalendarHelper
def calendar(date = Date.today,options={}, &block)
Calendar.new(self, date,options, block).table
end
class Calendar < Struct.new(:view, :date,:options, :callback)
HEADER = %w[SUN MON TUES WED THU FRI SAT]
START_DAY = :sunday
delegate :content_tag, to: :view
@jbmyid
jbmyid / .zshrc
Last active December 25, 2015 02:09
Common bash config and aliases for git
function git.branch {
br=`git branch | grep "*"`
echo ${br/* /}
}
function git.pull {
branch=`git.branch`
op=`git pull origin $branch`
}
function git.push {
@jbmyid
jbmyid / .zshrc
Last active December 25, 2015 02:09
zsh config file
# Path to your oh-my-zsh configuration.
ZSH=$HOME/.oh-my-zsh
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
ZSH_THEME="itg"
# Example aliases
f you installed postresql on your server then just host: localhost to database.yml, I usually throw it in around where it says pool: 5. Otherwise if it's not localhost definitely tell that app where to find its database.
development:
adapter: postgresql
encoding: unicode
database: kickrstack_development
host: localhost
pool: 5
username: kickrstack
password: secret
result = client.execute(:api_method => api_method, :parameters => {
'ids' => "ga:7174565581",
'start-date' => Date.new(1970,1,1).to_s,
'end-date' => Date.today.to_s,
'dimensions' => 'ga:pagePath',
'metrics' => 'ga:pageviews',
'filters' => 'ga:pagePath==/url/to/user'
})
Add these lines into ~/.gitconfig file.
---------------------------------------------------------------------
[alias]
st = status
ft = fetch
ci = commit
cm = commit -m
br = branch
@jbmyid
jbmyid / settings.js
Last active August 29, 2015 14:00 — forked from jcsrb/settings.js
/*
Add following in /home/usernam/.config/sublime-text-3/Packages/User/RubyTest.sublime-settings
If file not present then create one
in case you get errors like this
ruby:1: Invalid char `\x7F' in expression
ruby:1: Invalid char `\x01' in expression
ruby:1: Invalid char `\x01' in expression
ruby:1: Invalid char `\x01' in expression
ruby:1:in `<main>': uninitialized constant ELF (NameError)
class ApplicationController < ActionController::Base
...
#Problem:
#In rails 3.0.1+ it is no longer possible to do this anymore;
# rescue_from ActionController::RoutingError, :with => :render_not_found
#
#The ActionController::RoutingError thrown is not caught by rescue_from.
#The alternative is to to set a catch-all route to catch all unmatched routes and send them to a method which renders an error
#As in http://techoctave.com/c7/posts/36-rails-3-0-rescue-from-routing-error-solution
process :get_geometry
def geometry
@geometry
end
def get_geometry
if (@file)
img = ::Magick::Image::read(@file.file).first
@geometry = [ img.columns, img.rows ]
end
# spec/factories/my_files.rb
FactoryGirl.define do
factory :my_file do
photo Rack::Test::UploadedFile.new(File.open(File.join(Rails.root, '/spec/fixtures/myfiles/myfile.jpg')))
end
end