Skip to content

Instantly share code, notes, and snippets.

View lucascaton's full-sized avatar

Lucas Caton lucascaton

View GitHub Profile
@lucascaton
lucascaton / fix-wordpress-permissions.sh
Created September 10, 2016 07:28 — forked from Adirael/fix-wordpress-permissions.sh
Fix wordpress file permissions
#!/bin/bash
#
# This script configures WordPress file permissions based on recommendations
# from http://codex.wordpress.org/Hardening_WordPress#File_permissions
#
# Author: Michael Conigliaro <mike [at] conigliaro [dot] org>
#
WP_OWNER=www-data # <-- wordpress owner
WP_GROUP=www-data # <-- wordpress group
WP_ROOT=/var/www/lucascaton_blog
@lucascaton
lucascaton / oferta_irresistivel.md
Last active August 1, 2016 08:53
Crie sua Oferta Irresistível
%w(1 2).sort_by { |i| nil }
# => ["1", "2"]
# ...
%w(1 2 3 4 5 6).sort_by { |i| nil }
# => ["1", "2", "3", "4", "5", "6"]
### So far, so good...
### But look what happens when you have 7 or more elements:
@lucascaton
lucascaton / array.swift
Last active February 22, 2016 09:15
By using functions like the following, it prevents app from crashing if you pass the wrong index (tip from @CassiusPacheco)
public extension Array {
    public subscript(safe index: Int) -> Element? {
        return self.indices ~= index ? self[index] : nil
    }
}
// ...
let optionalResult = array[safe: 1] // returns nil instead of crashing
(1..50).to_a.first # => 1
(1..50).to_a.second # => 2
(1..50).to_a.third # => 3
(1..50).to_a.fourth # => 4
(1..50).to_a.fifth # => 5
(1..50).to_a.forty_two # => 42
#!/usr/bin/env ruby
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
require 'RMagick'
require 'capybara'
require 'launchy'
module Capybara::Recording
def start_recording
system "rm -f tmp/*"
end
def save_recording
@lucascaton
lucascaton / pre-commit
Created December 9, 2015 00:04 — forked from jonasschmidt/pre-commit
git pre-commit hook checking for RSpec :focus tags that were unintentionally left in the specs
#!/usr/bin/env ruby
if `git diff --cached spec` =~ /,\s?(:focus|focus:\s?true|:focus\s?=>\s?true)/
puts "\e[31mPlease focus and remove your :focus tags before committing :)"
exit 1
end
single quotes `1` x `0` double quotes
https://github.com/18F/C2/pull/705 ("enforce single quotes” PR ➙ merged!)
there’s also a good discussion here: https://github.com/bbatsov/ruby-style-guide/issues/96
the most popular ruby style guide recommends single quotes: https://github.com/bbatsov/ruby-style-guide#consistent-string-literals :stuck_out_tongue: