Skip to content

Instantly share code, notes, and snippets.

Avatar

Lucas Caton lucascaton

View GitHub Profile
View fix-wordpress-permissions.sh
#!/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 Aug 1, 2016
Crie sua Oferta Irresistível
View oferta_irresistivel.md
View sort_by.rb
%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 Feb 22, 2016
By using functions like the following, it prevents app from crashing if you pass the wrong index (tip from @CassiusPacheco)
View array.swift
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
View rails_is_awesome.rb
(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
View small_rails.rb
#!/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
View capybara-recording.rb
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 Dec 9, 2015 — forked from jonasschmidt/pre-commit
git pre-commit hook checking for RSpec :focus tags that were unintentionally left in the specs
View pre-commit
#!/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
View single quotes VS double quotes
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:
View github_labels_manager.rb
require 'octokit'
client = Octokit::Client.new login: 'username', password: 'password'
repos = []
page = 1
loop do
puts "Fetching repositories from page ##{page}"