Skip to content

Instantly share code, notes, and snippets.

@jonduarte
jonduarte / gist:1115975
Created July 30, 2011 20:49
Autotest for Cakephp
# Autotest for cakephp
# Adapted for linux-users by jonathan
# jonathan.duarte@rocketmail.com | tunecookies.tumblr.com
# Original article: http://www.amitsamtani.com/2010/05/09/cakephp-autotest-using-watchr/
#mude para o caminho da sua aplicação
$cake = "php /var/www/MINHA_APPLICACAO/cake/console/cake.php"
watch('app/(models|controllers)/(.*).php') { |m| test_changed_model_or_controller(m[0]) }
watch('app/tests/cases/(models|controllers)/(.*).test.php') { |m| test_changed_test_case(m[0]) }
require 'parslet'
require 'pp'
class Mini < Parslet::Parser
rule(:lparen) { str('(') >> space? }
rule(:rparen) { str(')') >> space? }
rule(:comma) { str(',') >> space? }
rule(:space) { match('\s').repeat(1) }
rule(:space?) { space.maybe }
require 'origami'
input = "sample.pdf"
mypdf = Origami::PDF.read input
#load certificate file
certificate_raw = File.read "server.crt"
certificate = OpenSSL::X509::Certificate.new certificate_raw
#load key file
# Installing old version of gem libv8 and therubyracer on mavericks
# Versions:
# libv8: 3.11.8.17
# therubyracer: 0.11.4
#
# Ref: http://www.motivatedcompany.com/post/65060531778/using-libv8-3-11-on-os-x-10-9-mavericks
git clone https://github.com/cowboyd/libv8.git
cd libv8
git checkout 3.11
# Cleanup old local branchs
git remote prune origin | awk -F "/" '{ print $2 }' | tail -n +3 | xargs git branch -d
# Install pg on mavericks
# Using Postgres app
export PATH="~/bin:/usr/local/bin:/usr/local/sbin:/Applications/Postgres93.app/Contents/MacOS/bin:$PATH"
gem install pg -v='0.14.0'
# Import pg dump to rails app
rake db:create:all
pg_restore -d app_development file.dump
# app/controllers/sessions_controller.rb
class SessionsController < ApplicationController
def create
authenticate!
render :json => {:status => "200", :message => "You have successfully logged in"}
end
private
def warden
request.env['warden']
@jonduarte
jonduarte / gist:8476817
Created January 17, 2014 16:49
How to add directories to `rake stats`
# Reference: http://ridingtheclutch.com/post/71345006944/how-to-add-directories-to-rake-stats
task :stats => "omakase:stats"
namespace :omakase do
task :stats do
require 'rails/code_statistics'
::STATS_DIRECTORIES << ["Services", "app/services"]
::STATS_DIRECTORIES << ["Services Tests", "test/services"]
CodeStatistics::TEST_TYPES << 'Services Tests'
@jonduarte
jonduarte / gist:8476862
Created January 17, 2014 16:52
Add custom folders to rake test
# Enhance rails test with lib directory
#
# http://www.seanbehan.com/how-to-add-additional-sub-directories-to-the-default-rails-testunit-file-structure
namespace :test do
Rake::TestTask.new(:lib) do |t|
t.libs << "test"
t.pattern = 'test/lib/**/*_test.rb'
t.verbose = true
end
require 'bundler/capistrano'
set :application, "net"
set :repository, "git@githost.com:net.git"
set :scm, :git
set :default_environment, {
'PATH' => "$HOME/.rbenv/shims:$HOME/.rbenv/bin:$PATH"
}