Skip to content

Instantly share code, notes, and snippets.

@imathis
imathis / task.rb
Created March 27, 2012 18:56
Edit Octopress post
desc "Edit a post (defaults to most recent)"
task :edit_post, :title do |t, args|
args.with_defaults(:title => false)
posts = Dir.glob("#{source_dir}/#{posts_dir}/*.*")
post = (args.title) ? post = posts.keep_if {|post| post =~ /#{args.title}/}.last : posts.last
if post
puts "Opening #{post} with #{editor}..."
system "#{ENV['EDITOR']} #{post} &"
else
puts "No posts were found with \"#{args.title}\" in the title."
@edubkendo
edubkendo / ctags_subl_coffee.md
Created June 9, 2012 15:11
Ctags, Sublime Text, Coffeescript

Ctags with Sublime Text and Coffeescript

Get Ctags

Step one is to install Exuberant Ctags on your system. For those on an Ubuntu system, this is as simple as:

sudo apt-get install ctags

Get the Sublime Text Plug-in

@carlosantoniodasilva
carlosantoniodasilva / worker_example_group.rb
Created February 15, 2012 22:59
RSpec - Register Example Group
module Support
module WorkerExampleGroup
include RSpec::Rails::RailsExampleGroup
def self.included(base)
base.metadata[:type] = :worker
end
end
end
@ibanez270dx
ibanez270dx / ConditionalValidations.rb
Last active April 10, 2018 11:31
A simple module that allows validation of only certain attributes of any given model. Created for CoverHound.com.
#
# At CoverHound, we use conditional validations all over the form. However, there is no proper way to do
# this in Rails. Instead, we can provide an array of attributes (validated_fields attribute)
# and ensure they are the only ones to get validated.
#
module ConditionalValidations
attr_accessor :validated_fields
def field_is_required?(field)
@tsmsogn
tsmsogn / primes.rb
Last active May 6, 2019 01:45
[ruby]Sieve of Eratosthenes with Ruby
def primes(max)
nums = Array.new(max + 1, 1)
nums[0] = nums[1] = 0
(2..Math.sqrt(max)).each do |sieve|
if nums[sieve] == 1
(2 * sieve).step(max, sieve).each do |num|
nums[num] = 0
end
end
@YoussefKababe
YoussefKababe / Dockerfile
Created September 15, 2014 04:00
Dockerfile to compile and install nginx with additional modules
FROM ubuntu:trusty
MAINTAINER Youssef Kababe "youssef.kbe@gmail.com"
RUN apt-get update
RUN apt-get install -y wget
RUN apt-get install -y libpcre3-dev
RUN apt-get install -y zlib1g-dev
RUN apt-get install -y make
RUN wget http://nginx.org/download/nginx-1.6.1.tar.gz
@AlexVPopov
AlexVPopov / clojure.spec cheat sheet.md
Last active February 21, 2020 07:08
A cheat sheet for clojure.spec

clojure.spec cheat sheet

Specs

Require

(ns my.ns
  (:require [clojure.spec.alpha :as s]))
@nov
nov / token_request_sample.rb
Created March 23, 2011 17:29
Rack::OAuth2::Client Sample - Token Request
require 'rubygems'
require 'rack/oauth2'
client = Rack::OAuth2::Client.new(
:identifier => YOUR_CLIENT_ID,
:secret => YOUR_CLIENT_SECRET,
:redirect_uri => YOUR_REDIRECT_URI, # only required for grant_type = :code
:host => 'rack-oauth2-sample.heroku.com'
)
@rmm5t
rmm5t / OUTPUT.md
Last active February 19, 2021 21:18
How to properly introduce a new counter_cache to an existing Rails project.

Fast/efficient approach:

-- execute("UPDATE posts SET comments_count = (SELECT count(1) FROM comments WHERE comments.post_id = posts.id)")
   -> 1.3197s

Slow/naïve approach:

@bjornharrtell
bjornharrtell / Coffeescript ctags
Created June 9, 2012 17:14 — forked from yury/Coffeescript ctags
ctags definitions for coffeescript. Detects classes, static/class methods, fields, static fields, plain functions, variables.
--langdef=coffee
--langmap=coffee:.coffee
--regex-coffee=/(^|=[ \t])*class ([A-Za-z]+\.)*([A-Za-z]+)( extends [A-Za-z.]+)?$/\3/c,class/
--regex-coffee=/^[ \t]*(module\.)?(exports\.)?@?([A-Za-z.]+):.*[-=]>.*$/\3/m,method/
--regex-coffee=/^[ \t]*(module\.)?(exports\.)?([A-Za-z.]+)[ \t]+=.*[-=]>.*$/\3/f,function/
--regex-coffee=/^[ \t]*([A-Za-z.]+)[ \t]+=[^->\n]*$/\1/v,variable/
--regex-coffee=/^[ \t]*@([A-Za-z.]+)[ \t]+=[^->\n]*$/\1/f,field/
--regex-coffee=/^[ \t]*@([A-Za-z.]+):[^->\n]*$/\1/f,static field/
--regex-coffee=/^[ \t]*([A-Za-z.]+):[^->\n]*$/\1/f,field/
--regex-coffee=/(constructor: \()@([A-Za-z.]+)/\2/f,field/