Skip to content

Instantly share code, notes, and snippets.

@PragmaticEd
PragmaticEd / Vagrantfile
Created July 21, 2016 13:22 — forked from spacecowb0y/Vagrantfile
Vagrant config to setup a rvm + ruby + rails + passenger + nginx + mysql.
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "precise32"
config.vm.box_url = "http://files.vagrantup.com/precise32.box"
config.vm.network :forwarded_port, guest: 3000, host: 3000
config.vm.hostname = "ruby-dev-server"
config.vm.provision :shell, path: "install.sh"
@PragmaticEd
PragmaticEd / Make downcase, upcase, capitalize methods work with non UNICODE characters (like Russian).md
Created July 28, 2016 12:38
Make downcase, upcase, capitalize methods work with non UNICODE characters (like Russian)
str = 'Привет'

puts str          # => Привет
puts str.downcase # => Привет

using active_support

require 'active_support/all' # not required inside Rails app
function apt_download() {
PACKAGE=$1
URI=`apt-cache show $PACKAGE | grep "Filename:" | cut -f 2 -d " "`
wget http://archive.ubuntu.com/ubuntu/$URI
}
@PragmaticEd
PragmaticEd / windows_ubuntu.md
Created September 22, 2016 11:12
Windows Ubuntu

reinstall: lxrun /install /y

Uninstall: lxrun /uninstall /full /y

Uninstall, but keep user folder: lxrun /uninstall /y

find /var/www -not -type d -exec file "{}" ";" | grep CRLF
# Make nano default editor:
git config --global core.editor 'nano'
# git log2 | better log (one liners):
git config --global alias.log2 "log --pretty=format:'%C(yellow) %h %C(cyan) %cd %C(white) %s %C(red) (%an)'"
# git network | network (github network in terminal):
git config --global alias.network "log -20 --pretty=format:'%C(yellow)%h%Creset\\ %C(green)%ar%C(cyan)%d\\ %Creset%s%C(yellow)\\ [%cn]' --graph --decorate --all"
@PragmaticEd
PragmaticEd / application.rb
Created February 23, 2017 07:01 — forked from steve9001/application.rb
Rails middleware to provide information about errors during requests
module MyApp
class Application < Rails::Application
if Rails.env == 'test'
require 'diagnostic'
config.middleware.use(MyApp::DiagnosticMiddleware)
end
end
end
@PragmaticEd
PragmaticEd / precompile.md
Created March 10, 2017 09:59 — forked from mrbongiolo/precompile.md
HOW TO: Rails 4.2 add 'vendor/asset' to precompile list

To enable the precompilation of all non.js/.css assets within vendor/assets just add this to config/initializers/assets.rb:

Rails.application.config.assets.precompile << Proc.new { |path, fn| fn =~ /vendor\/assets/ && !%w(.js .css).include?(File.extname(path)) }

Be aware that this will precompile ALL non .js/.css assets that you have there, some plugins or libraries might have .txt or other files around, and those would end up into your precompiled list also.

If you need to precompile images only, you could use this:

Rails.application.config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif)
@PragmaticEd
PragmaticEd / generate.rb
Last active May 6, 2017 14:05
Generate bootstrap-like padding & margin classes
minify = true
px_steps = 2
min_px = 0
max_px = 200
# ----------------------------------------------------------------------------------------
margin_css = ''
padding_css = ''
arr = ([0] + (min_px..max_px).step(px_steps).to_a + [max_px]).uniq # make sure min and max are included
@PragmaticEd
PragmaticEd / puma_ssl.sh
Last active May 22, 2017 20:42
Run Puma server with https
# 1) Create your private key (any password will do, we remove it below)
$ cd ~/.ssh
$ openssl genrsa -des3 -out server.orig.key 2048
# 2) Remove the password
$ openssl rsa -in server.orig.key -out server.key