This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*/5 * * * * aws cloudwatch put-metric-data --metric-name MyPassengerCount --namespace "System/Linux" --dimensions "InstanceId=$(ec2metadata --instance-id)" --unit Count --value $(ps ax | grep "[P]assenger RackApp" | wc -l) | |
*/5 * * * * aws cloudwatch put-metric-data --metric-name MyDJWorkersCount --namespace "System/Linux" --dimensions "InstanceId=$(ec2metadata --instance-id)" --unit Count --value $(ps ax | grep "[d]elayed_job" | wc -l) | |
*/5 * * * * aws cloudwatch put-metric-data --metric-name MyCometServerCount --namespace "System/Linux" --dimensions "InstanceId=$(ec2metadata --instance-id)" --unit Count --value $(ps ax | grep "[b]randrep_comet_server" | wc -l) | |
# N of Passenger processed that older then 1 hour | |
*/30 * * * * aws cloudwatch put-metric-data --metric-name MyOldPassengerCount --namespace "System/Linux" --dimensions "InstanceId=$(ec2metadata --instance-id)" --unit Count --value $(ps axo etimes,args | grep "RackApp" | awk '{if ($1 >= (1 * 3600)) print $0}' | wc -l) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
COOKIE = ARGV[0] | |
TO = ARGV[1] || 'json/bookmarks' | |
`mkdir -p #{TO}` | |
%w{films serials books games person}.each do |type| | |
print "#{type} " | |
(1..99).each do |page| | |
json = `curl 'http://#{type}.imhonet.ru/web.php?path=favorites/all/&domain=#{type}&page=#{page}' --silent -H '#{COOKIE}' -H 'Accept-Encoding: gzip, deflate, sdch' -H 'Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36' -H 'Accept: application/json' -H 'Referer: http://films.imhonet.ru/favorites/all/' -H 'X-Requested-With: XMLHttpRequest' -H 'Connection: keep-alive' --compressed` | |
break unless json[0] == '{' # if content is not json, then pager ended | |
print '.' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# recursive freeze of hash, array | |
module DeepFreeze | |
extend self | |
def freeze(obj_or_enumerable) | |
if obj_or_enumerable.respond_to?(:each) | |
obj_or_enumerable.each { |v| DeepFreeze.freeze(v) } | |
end | |
obj_or_enumerable.freeze | |
obj_or_enumerable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT CONCAT(table_schema, '.', table_name), CONCAT(ROUND(table_rows / 1000000, 2), 'M') rows, CONCAT(ROUND(data_length / ( 1024 * 1024 * 1024 ), 2), 'G') DATA, CONCAT(ROUND(index_length / ( 1024 * 1024 * 1024 ), 2), 'G') idx, CONCAT(ROUND(( data_length + index_length ) / ( 1024 * 1024 * 1024 ), 2), 'G') total_size, ROUND(index_length / data_length, 2) idxfrac FROM information_schema.TABLES ORDER BY data_length + index_length DESC LIMIT 20; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
listen 80 default_server; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header Host $host; | |
location / { | |
proxy_pass http://desthost.com; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module UpdateIgnore | |
def update_ignore(updates, conditions) | |
set = updates.map{|k,v| "#{connection.quote_column_name(k)} = #{connection.quote v}" }.join(', ') | |
connection.update "UPDATE IGNORE #{quoted_table_name} SET #{set} WHERE #{self.where(conditions).where_clauses.join('AND')}" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ActiveRecordSelectAttributesExtension | |
# Returns an array of arrays containing the field values. | |
# Order is the same as that returned by +columns+. | |
# select_rows("id, type") => [[1, 'one'], [2, 'one'], [3, 'two']] | |
def select_rows(fields = nil) | |
scope = fields ? self.scoped.select(fields) : self.scoped | |
connection.select_rows(scope.to_sql) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationController < ActionController::Base | |
include ColorizedPrint if Rails.env.development? | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# download video from youtube subscription | |
# depends: youtube-dl | |
# OS: windows | |
require 'open-uri' | |
require 'hpricot' | |
USERNAME = '' | |
YOUTUBE_DL_PATH = "python C:\\programs\\Video\\youtube\\youtube-dl\\youtube-dl.py" | |
YOUTUBE_DL_PARAMS = "--retries=30 --max-quality=22 -c -i -w" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -silent http://checkip.dyndns.org | grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}' | pbcopy |