Skip to content

Instantly share code, notes, and snippets.

@ivalentinee
ivalentinee / fig.yml
Last active August 29, 2015 14:11
fig.yml for Rails application
db:
image: postgres
ports:
- "5432"
mailcatcher:
image: simpledrupalcloud/mailcatcher:latest
hostname: mailcatcher
ports:
- "1080:1080"
@ivalentinee
ivalentinee / shell-I-play.sh
Last active September 2, 2015 08:52
playing with grep/sed/tail/etc...
# most hungry processes (no, htop is too mainstream)
ps aux --sort -rss | head -n 10 | sed 's/[^ ]* *[0-9]* *\([0-9\.]*\) *\([0-9\.]*\) *[0-9]* *[0-9]* *? *[SsLl]* *[^ ]* *[^ ]* *\([^ ]*\).*/processor: \1%, memory: \2%, process: \3/'
# fix unzipped files with russian names in current directory
find . -type f -exec sh -c 'np=`echo {}|iconv -f cp1252 -t cp850| iconv -f cp866`; mv "{}" "$np"' \;
@ivalentinee
ivalentinee / MoneyRails user input workaround.rb
Last active September 10, 2015 06:50
MoneyRails user input workaround
class PaymentInput < SimpleForm::Inputs::Base
def input(wrapper_options)
custom_input_options = { value: value, maxlength: 16 }
merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
merged_input_options = merge_wrapper_options(custom_input_options, merged_input_options)
@builder.text_field(attribute_name, merged_input_options)
end
def value
before_type_cast_value = object.send("#{attribute_name}_money_before_type_cast")
@ivalentinee
ivalentinee / test:extensions:carrier_wave.rb
Created September 30, 2015 10:55
Fix CarrierWave to work with filenames (not files) for tests — doesn't pollute public/uploads folder
# Fix CarrierWave to work with filenames (not files)
module CarrierWave::Uploader::Cache
def cache!(filename)
@file = CarrierWave::SanitizedFile.new(File.open(filename))
@filename = filename
end
end
# Write your default config options here!
## outputs
# ao=alsa:device=hw=3.0
# ao=pulse
# vo=fbdev2
## screen
monitoraspect="16:9"
stop-xscreensaver="yes"
docker_compose_exec() {
docker exec -it $(docker-compose ps | grep $1 | awk '{print $1}') ${@:2}
}
alias dcrun='docker_compose_exec web'
alias dcenter='docker_compose_exec web bash'
alias dcenter_new='docker-compose run web bash' # if container is not up
@ivalentinee
ivalentinee / Dockerfile_sbcl
Last active July 15, 2016 20:45
Sample sbcl dockerfile
FROM ubuntu
RUN apt-get update -qq
RUN apt-get install -y sbcl
RUN apt-get install -y build-essential curl
RUN curl -O https://beta.quicklisp.org/quicklisp.lisp
RUN sbcl --load quicklisp.lisp --eval '(quicklisp-quickstart:install)'
RUN mkdir -p /app/
@ivalentinee
ivalentinee / convert-subs.sh
Created November 11, 2017 15:47
Convert subtitles coding system
#!/bin/bash
FILES=*.srt
for f in $FILES
do
echo "Processing $f file..."
iconv -c -f WINDOWS-1251 -t UTF-8 "$f" -o "$f"
done
print_trace = fn(print_trace, fd) ->
receive do
msg ->
:io.format(fd, "call: (tracer pid: ~p)~n ~p~n", [self(), msg])
print_trace.(print_trace, fd)
end
end
{ok, fd} = :file.open("/tmp/trace.out", [:write])
custom_tracer = :proc_lib.spawn(fn -> print_trace.(print_trace, fd) end)
export TIME="====== Time report\ncommand: %C\nreal: %E\nuser: %U\nsys: %S\nFilesystem inputs: %I\nAverage memory usage: %Mk\nAverage CPU usage: %P\n======"