Skip to content

Instantly share code, notes, and snippets.

@hardlin3r
hardlin3r / puma.service
Created October 4, 2017 20:35 — forked from arteezy/puma.service
Manage Puma with systemd on Ubuntu 16.04 and rbenv
[Unit]
Description=Puma Rails Server
After=network.target
[Service]
Type=simple
User=deploy
WorkingDirectory=/home/deploy/app/current
ExecStart=/home/deploy/.rbenv/bin/rbenv exec bundle exec puma -C /home/deploy/app/shared/config/puma.rb
ExecStop=/home/deploy/.rbenv/bin/rbenv exec bundle exec pumactl -S /home/deploy/app/shared/tmp/pids/puma.state stop
@hardlin3r
hardlin3r / database_cleaner.rb
Created September 11, 2017 14:31 — forked from jsteiner/database_cleaner.rb
Database Cleaner
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
config.before(:each, js: true) do
@hardlin3r
hardlin3r / active_record_enum_with_rails_admin.rb
Created September 5, 2017 19:38 — forked from dmilisic/active_record_enum_with_rails_admin.rb
Initializer for handling ActiveRecord (4.1+) enums by RailsAdmin (0.6.2)
module ActiveRecord
module RailsAdminEnum
def enum(definitions)
super
definitions.each do |name, values|
define_method("#{ name }_enum") { self.class.send(name.to_s.pluralize).to_a }
define_method("#{ name }=") do |value|
if value.kind_of?(String) and value.to_i.to_s == value
namespace :figaro do
desc "SCP transfer figaro configuration to the shared folder"
task :setup do
on roles(:app) do
upload! "config/application.yml", "#{shared_path}/application.yml", via: :scp
end
end
desc "Symlink application.yml to the release path"
task :symlink do
@hardlin3r
hardlin3r / how_to_localize_rails_views.md
Last active August 21, 2017 11:01
Как делать локализацию rails приложений, гайд для фронтендеров и переводчиков

Локализация рейлс приложений на примере slim view templates

h1 Hello world!

для локализации заменяем текст на ключ 'hello' и отдаем его в функцию t

h1 =t('hello')

и записываем ключ с соответствующим ему текстом в config/locales/en.yml

@hardlin3r
hardlin3r / commands
Created August 18, 2017 11:16
prepare ubuntu for rails deploy
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev
#install rbenv
#install ruby-build
#install ruby via rbenv
#install bundler
sudo apt-get install postgresql postgresql-contrib libpq-dev
# sudo apt-get install imagemagick libmagickcore-dev libmagickwand-dev
@hardlin3r
hardlin3r / octave.md
Created March 26, 2017 22:25 — forked from obstschale/octave.md
An Octave introduction cheat sheet.

Octave CheatSheet

GNU Octave is a high-level interpreted language, primarily intended for numerical computations.
(via GNU Octave)

Basics

  • not equal ~=
  • logical AND &&
@hardlin3r
hardlin3r / utility.txt
Created March 26, 2017 01:09
must have utilities for linux administration
tcpdump
lsof - show all opened descriptors
top - show how much user and system time current processes are using
strace - show all syscalls called by the application
iostat - report io statistics
netstat - show all opened network connections
limits.conf - set limits to users
ulimit
sysctl - configure kernel parameters
pstack - print stack trace of running process
@hardlin3r
hardlin3r / index.erl
Created March 19, 2017 19:22
create reverse index for a text file
-module(index).
-export([get_file_contents/1,show_file_contents/1, index/1]).
% Used to read a file into a list of lines.
% Example files available in:
% gettysburg-address.txt (short)
% dickens-christmas.txt (long)
index(Name) ->
Words = words(get_file_contents(Name)),
lists:filter(fun({W, _}) -> length(W) >= 3 end, lists:sort(fun({W1, _}, {W2, _}) -> W1 < W2 end, index_from_words(Words))).
sudo apt-get update
sudo locale-gen "en_US.UTF-8"
in /etc/default/locale:
LC_ALL=en_US.UTF-8
LANG=en_US.UTF-8
sudo apt-get install git-core build-essential libssl-dev libreadline-dev zlib1g-dev nodejs postgresql libxml2-dev libxslt1-dev
postgresql-server-dev-9.3 curl python-software-properties libcurl4-openssl-dev
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc