Skip to content

Instantly share code, notes, and snippets.

Avatar
💡
I'll do my best

Douglas douglasresende

💡
I'll do my best
View GitHub Profile
View security.conf
# config to don't allow the browser to render the page inside an frame or iframe
# and avoid clickjacking http://en.wikipedia.org/wiki/Clickjacking
# if you need to allow [i]frames, you can use SAMEORIGIN or even set an uri with ALLOW-FROM uri
# https://developer.mozilla.org/en-US/docs/HTTP/X-Frame-Options
add_header X-Frame-Options SAMEORIGIN;
# when serving user-supplied content, include a X-Content-Type-Options: nosniff header along with the Content-Type: header,
# to disable content-type sniffing on some browsers.
# https://www.owasp.org/index.php/List_of_useful_HTTP_headers
# currently suppoorted in IE > 8 http://blogs.msdn.com/b/ie/archive/2008/09/02/ie8-security-part-vi-beta-2-update.aspx
@douglasresende
douglasresende / slugify.exs
Created Jan 17, 2019 — forked from serradura/slugify.exs
Elixir slugify functions
View slugify.exs
defmodule Slug1 do
def slugify(input), do: map_slug(input, %{pattern: ~r/\s+/})
def slugify2(input), do: map_slug(input, %{pattern: " "})
defp map_slug(input, %{pattern: pattern}) do
input
|> to_string()
|> String.trim()
|> String.downcase()
@douglasresende
douglasresende / fp_01.rb
Created Jan 17, 2019 — forked from serradura/fp_01.rb
Examples of how Ruby 2.6 is more functional than ever! 👏🎉🚀
View fp_01.rb
raise 'Wrong Ruby version!' unless RUBY_VERSION >= '2.6.0'
module Strings
Trim = -> str { String(str).strip }
Replace = -> (sub, new_sub, str) { String(str).gsub(sub, new_sub) }
LowerCase = -> str { String(str).downcase }
end
# -- Alternative syntax --
Slugify = # Slugify =
@douglasresende
douglasresende / webpacker_rails.md
Created Aug 16, 2018 — forked from maxivak/webpacker_rails.md
Webpack, Yarn, Npm in Rails
View webpacker_rails.md
@douglasresende
douglasresende / IMfromsource.md
Created Apr 20, 2018 — forked from makenova/IMfromsource.md
Install ImageMagick from source on Ubuntu 14.04
View IMfromsource.md

Install ImageMagick from source on Ubuntu 14.04

The version of ImageMagick that is installed when you run apt-get install imagemagick on Ubuntu 14.04 is older than I would like.

$ convert --version
Version: ImageMagick 6.7.7-10 2016-06-01 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
Features: OpenMP
View DigitalOcean_S5.md

DigitalOcean S5

  • 5$
  • 1 CPU
  • 512Mb memory
  • 1T transfer
  • 20GB SSD

CPU info

View faster-unit-testing-in-rails-without-rails.rb
# Running a single minimalistic unit test with Rails 4 and Ruby 2.1.1 is a lot faster
# if you avoid loading Rails:
# Running the test *with* Rails
time ruby -Itest test/models/my_model_test.rb # => real ~ 6s
# Running the test *without* Rails
time ruby -Itest/no_rails test/models/my_model_test.rb # => real ~ 0.6s
@douglasresende
douglasresende / deploy.rb
Created Oct 26, 2017 — forked from andruby/deploy.rb
Start and Stop tasks for resque workers, with capistrano deploy hook (without God)
View deploy.rb
after "deploy:symlink", "deploy:restart_workers"
##
# Rake helper task.
# http://pastie.org/255489
# http://geminstallthat.wordpress.com/2008/01/27/rake-tasks-through-capistrano/
# http://ananelson.com/said/on/2007/12/30/remote-rake-tasks-with-capistrano/
def run_remote_rake(rake_cmd)
rake_args = ENV['RAKE_ARGS'].to_s.split(',')
cmd = "cd #{fetch(:latest_release)} && #{fetch(:rake, "rake")} RAILS_ENV=#{fetch(:rails_env, "production")} #{rake_cmd}"
@douglasresende
douglasresende / docker-compose.yml
Created Aug 11, 2017 — forked from tebeka/docker-compose.yml
HAProxy in front of Elasticsearch
View docker-compose.yml
elastic:
image: elasticsearch
haproxy:
image: haproxy
volumes:
- ${PWD}:/usr/local/etc/haproxy
links:
- elastic
ports: