Skip to content

Instantly share code, notes, and snippets.

View sponomarev's full-sized avatar
🔴
Offline

Sergey Ponomarev sponomarev

🔴
Offline
View GitHub Profile
@sponomarev
sponomarev / rinkeby.txt
Last active August 16, 2017 08:19
My Rinkeby testnet address
0x6aCD39459093E3d0D44e70878c52EE2ab047F5ba
### Keybase proof
I hereby claim:
* I am sponomarev on github.
* I am bufo_alvarius (https://keybase.io/bufo_alvarius) on keybase.
* I have a public key ASAOXoZrbrgw1juODSiV0ro3I2sZftnZbFg3FCJmPyChBQo
To claim this, I am signing this object:
@sponomarev
sponomarev / documents.rb
Last active August 29, 2015 14:17 — forked from dhh/documents.rb
# config/routes.rb
resources :documents do
scope module: 'documents' do
resources :versions do
post :restore, on: :member
end
resource :lock
end
end
@sponomarev
sponomarev / convert.sh
Created October 17, 2014 09:22
convert any source video to fixed size flv with coloured letterboxes
# params: $input, $output, $width, $height, $color
# for landscape (normal) orientation
ffmpeg -y -i $input -vcodec flv1 -vf "scale=iw*min($width/iw\,$height/ih):ih*min($width/iw\,$height/ih), pad=$width:$height:($width-iw*min($width/iw\,$height/ih))/2:($height-ih*min($width/iw\,$height/ih))/2:color=$color" -vb 4000k -acodec mp3 -ar 44100 -ab 320k -vsync 1 -async 1 $output
# for portrait orientation
ffmpeg -y -i $input -vcodec flv1 -vf "transpose=1, scale=iw*min($width/iw\,$height/ih):ih*min($width/iw\,$height/ih), pad=$width:$height:($width-iw*min($width/iw\,$height/ih))/2:($height-ih*min($width/iw\,$height/ih))/2:color=$color" -vb 4000k -acodec mp3 -ar 44100 -ab 320k -vsync 1 -async 1 $output
@sponomarev
sponomarev / ddos.sh
Created September 15, 2014 07:13
Usefull commands when you are under ddos
# Позволяет получить общую картину: распределение уникальных IP, с которых идут запросы, кол-во запросов с одного IP и т.д.
tail -f /var/log/nginx/nginx.access.log | cut -d ' ' -f 1 | logtop
# Покажет распределение какой-либо строки по IP в логе.
grep "&key=" /var/log/nginx/nginx.access.log | cut -d ' ' -f 1 | sort | uniq -c | sort -n | tail -n 30
# С какого ip сколько запросов
netstat -ntu | awk '{print $5}'| cut -d: -f1 | sort | uniq -c | sort -nr | more
@sponomarev
sponomarev / show_biggest_tables.sql
Created August 4, 2014 09:25
PG biggest table in database
-- Show biggest tables in your database
SELECT nspname || '.' || relname AS "relation",
pg_size_pretty(pg_total_relation_size(C.oid)) AS "total_size"
FROM pg_class C
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
WHERE nspname NOT IN ('pg_catalog', 'information_schema')
AND C.relkind <> 'i'
AND nspname !~ '^pg_toast'
ORDER BY pg_total_relation_size(C.oid) DESC
LIMIT 20;
@sponomarev
sponomarev / query_management.sql
Last active August 29, 2015 14:04
PG query management in simple query snippets
-- This queries were tested on PostgreSQL 9.3.4
-- Provides detailed information about servers current connections
SELECT datname as database,
pid,
user as username,
application_name as application,
client_addr as client_address,
query
FROM pg_stat_activity;
@sponomarev
sponomarev / sidekiq_stats_reset.rb
Last active June 30, 2017 20:28
Reset Sidekiq Stats
# Reset processed counter
Sidekiq.redis { |c| c.del('stat:processed') }
# Reset failed counter
Sidekiq.redis { |c| c.del('stat:failed') }
# Reset all redis database with counters, history and current queues
Sidekiq.redis { |c| c.flushdb }
@sponomarev
sponomarev / policy.json
Last active April 19, 2017 00:46
AllowPublicRead S3 bucket policy
{
"Id":"AllowPublicRead",
"Statement":[
{
"Sid":"AllowPublicRead",
"Action":[
"s3:GetObject"
],
"Effect":"Allow",
"Resource":"arn:aws:s3:::your-bucket-name/*",
# oj gem
gem 'oj'
gem 'oj_mimic_json' # we need this for Rails 4.1.x