Skip to content

Instantly share code, notes, and snippets.

@brain-geek
brain-geek / gist:46a7b2e6871710d378f8eaeeb414c099
Created January 22, 2021 22:19
Fast postgresql pg_dump and restore with progress bar
# If you don't have pv - install it for the import progress bar
brew install pv
# For relatively fast export as executable SQL, use:
# For partial export you can set list of exported tables, for example -t products -t stores
PGPASSWORD="<database_password>" pg_dump --format=plain --clean --no-owner --no-privileges --if-exists <db_name> -h <hostname> -U <username> -f <filename.sql>
# To watch on file size (if you know expected DB size), you can use
wc "ls -lAh *.sql"
@brain-geek
brain-geek / message_operations.ex
Last active March 24, 2016 08:51
ESpec phoenix channels early example
defmodule MessageOperations do
@doc """
Spawns process with possibility to wait for messages.
Returns pid.
## Examples
mb_pid = MessageOperations.start_mock_messagebox
send(mb_pid, :something)
MessageOperations.flush_messages(mb_pid)
@brain-geek
brain-geek / gist:5458187
Created April 25, 2013 07:55
Stacktrace for rabbitmq failure
# cat /var/log/rabbitmq/startup_*
Crash dump was written to: erl_crash.dump
Kernel pid terminated (application_controller) ({application_start_failure,kernel,{shutdown,{kernel,start,[normal,[]]}}})
{error_logger,{{2013,4,25},{6,59,17}},"Protocol: ~p: register error: ~p~n",["inet_tcp",{{badmatch,{error,epmd_close}},[{inet_tcp_dist,listen,1,[{file,"inet_tcp_dist.erl"},{line,70}]},{net_kernel,start_protos,4,[{file,"net_kernel.erl"},{line,1314}]},{net_kernel,start_protos,3,[{file,"net_kernel.erl"},{line,1307}]},{net_kernel,init_node,2,[{file,"net_kernel.erl"},{line,1197}]},{net_kernel,init,1,[{file,"net_kernel.erl"},{line,357}]},{gen_server,init_it,6,[{file,"gen_server.erl"},{line,304}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,227}]}]}]}
{error_logger,{{2013,4,25},{6,59,17}},crash_report,[[{initial_call,{net_kernel,init,['Argument__1']}},{pid,<0.20.0>},{registered_name,[]},{error_info,{exit,{error,badarg},[{gen_server,init_it,6,[{file,"gen_server.erl"},{line,320}]},{proc_lib,init_p_do_apply,3,[{
@brain-geek
brain-geek / clean
Last active December 16, 2015 08:38
Removing virus from infected flash drives.
attrib -R -A -H -S /s /d *
del /f "Removable Disk (1GB).lnk"
del /f "Removable Disk (2GB).lnk"
del /f "Removable Disk (4GB).lnk"
del /f "Removable Disk (8GB).lnk"
del /f autorun.inf
del /f /p *.init
del /f desktop.ini
del /f Thumbs.db
@brain-geek
brain-geek / nginx.conf
Created May 11, 2012 12:23
nginx virtual host config for unicorn
server {
server_name <sitename>;
root /home/<user>/app/current/public;
try_files $uri/index.html $uri.html $uri @app;
location @app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
@brain-geek
brain-geek / unicorn.rb
Created May 11, 2012 12:19
Unicorn simple config
rails_env = ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'production'
rails_root = ENV['RAILS_PATH'] || File.dirname(File.expand_path(File.dirname(__FILE__)))
pid_path = File.join(rails_root, 'tmp', 'pids', 'unicorn.pid')
old_pid = File.join(rails_root, 'tmp', 'pids', 'unicorn.pid.oldbin')
out_path = File.join(rails_root, 'log', 'unicorn')
working_directory rails_root
worker_processes (rails_env == 'production' ? 3 : 2)
preload_app true
@brain-geek
brain-geek / unicorn.rake
Created April 11, 2012 11:38
Rake task for unicorn startup
namespace :unicorn do
def rails_root
ENV['RAILS_PATH'] || rails_root
end
def unicorn_pid
File.join(rails_root, 'tmp', 'pids', 'unicorn.pid')
end
def unicorn_config
File.join(rails_root, 'config', 'unicorn.rb')
@brain-geek
brain-geek / gist:1791738
Created February 10, 2012 19:01
Mass replace assets hardcoded urls to rails helpers for sublime text
CSS:
Find What:
url\(../images/([^\)]+)\)
Replace with:
url(<%= asset_path '$1' %>)