Skip to content

Instantly share code, notes, and snippets.

@johnkoht
johnkoht / grid.css.sass
Last active January 1, 2022 23:21
Bootstrap 3 Style Grid built on Bourbon Neat
// Main containers
.container
@include outer-container
// Rows
.row
@include row()
// A basic column without a defined width or height
@johnkoht
johnkoht / config.rb
Created January 31, 2015 22:50
Paginating categories in middleman blog
# In config.rb
def get_locals(category, total_pages, i, articles, total_articles)
prev_page = false
# Is the a previous page and if so what does it look like
if (i - 1) == 1
prev_page = "/blog/categories/#{category}"
elsif (i - 1) > 1
prev_page = "/blog/categories/#{category}/page/#{i-1}"
end
@johnkoht
johnkoht / date_time.rb
Last active December 22, 2015 22:49
Adds ActiveSupport convenience method for Date and Time objects for identifying if a date is within this year or not.
# Patch for Date and Time that adds a conveneince method for identifying
# if a date is within this year
# config/initializers/date_time.rb
class Date
def this_year?
self.year == ::Date.current.year
end
end
# In your deploy.rb add the following code. This will run the rake task
# when deployment beings
before :deploy do
run_locally 'rake sms:send["We\'re doing the thing - kohbot"]'
end
# And then send another after the deployment is over
after :deploy do
run_locally 'rake sms:send["The thing is over :( - kohbot)"]'
end
@johnkoht
johnkoht / sms.rake
Last active December 14, 2015 15:48
Capistrano deployment notifications via SMS
# Create a rake task that sends the message using Twilio. You'll
# need a Twilio SID and Token as well as number
namespace :sms do
desc "Send SMS message"
task :send, [:message] => [:environment] do |t, args|
client = Twilio::REST::Client.new TWILIO_SID, TWILIO_TOKEN
client.account.sms.messages.create(
from: TWILIO_NUMBER,
to: PHONE_NUMBER,
body: args[:message]
@johnkoht
johnkoht / patch_arracy.rb
Last active December 14, 2015 06:09
Monkey patch Array so that we can find values. Used when caching some arrays
class Array
# Given an Array, find if a value exists for a given key. This is helpful in our settings
# since we cache the entire settings array, but occasionally we wan to find a specific
# setting, i.e. "Site Title", "Posts per page", etc....
# USAGE::: array.find_value? "key", "Value is Case Sensitive"
def find_value key, value
if self.first.respond_to? key.parameterize.underscore.to_sym
self.select { |item| item.send(key.parameterize.underscore) == value }.first rescue nil
@johnkoht
johnkoht / emailitize.rb
Created February 26, 2013 00:21
Little script that takes a string and will return the same string but with email addresses encoded and hyperlinked
# takes a string and will return the same string but with email addresses encoded and hyperlinked
def emailitize text
text.gsub(/([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})/i) {|m|
mail_to(m, m.gsub("@", "[at]"), :encode=>:hex)
}
end
@johnkoht
johnkoht / Rails Common Scopes
Created July 18, 2012 00:33
Rails Apps Common Scopes
module CommonScopes
def self.included(base)
base.class_eval {
# Filtering by the state of the record
scope :active, where(:parent_id => nil, :deleted_at => nil) #.order('sort_order asc')
scope :published, where('published_at IS NOT NULL', :deleted_at => nil)
scope :unpublished, where(:published_at => nil, :deleted_at => nil)
$(document).ready(function() {
var topspeed = 1;
var midspeed = 1;
var bgspeed = 1;
var bgfactor = .1;
var distanceFactor = 1.2;
var useDistance = true;
if (!$.browser.webkit) {
@johnkoht
johnkoht / gist:1613646
Created January 15, 2012 00:51
Oi'vangelist API
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="language" content="en" />
<title>kohactive | a creative digital company</title>
<meta name="robots" content="noindex,nofollow " />