Skip to content

Instantly share code, notes, and snippets.

Michael Mahemoff mahemoff

Block or report user

Report or block mahemoff

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mahemoff
mahemoff / bench.rb
Last active Mar 11, 2018
Benchmarking performance of persistent HTTP requests
View bench.rb
#!/usr/bin/env ruby
require 'uri'
require 'net/http'
require 'benchmark'
# dummy fetch first URL to baseline setup (ensures DNS and any routing
# optimisations done)
def prime_fetching(urls)
ignored = Net::HTTP.get_response(URI(urls.first))
end
@mahemoff
mahemoff / MySQL monitoring
Last active Jan 28, 2018
MySQL one-liner for monitoring long queries on the console
View MySQL monitoring
+---------+--------+------------+-------------------+---------+------+----------+------------------------------------------------------------------------------------------------------------------------------+
| ID | USER | HOST | DB | COMMAND | TIME | STATE | QUERY |
+---------+--------+------------+-------------------+---------+------+----------+------------------------------------------------------------------------------------------------------------------------------+
| 2786271 | appy | borg:89700 | global_app_center | Query | 12 | updating | SELECT `posts` FROM `blog` WHERE `authors`.`id` IN ( 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2.. | |
+---------+--------+------------+-------------------+---------+------+----------+---------------------------------------------------------------------
@mahemoff
mahemoff / gist:f828acf69bd00d8db06b085221c92b3e
Created Oct 12, 2017
AWS backup folder from command-line with compression and encryption
View gist:f828acf69bd00d8db06b085221c92b3e
### Install Python and aws
[pip install awscli](https://docs.aws.amazon.com/cli/latest/userguide/installing.html)
You may need to add it to your path, e.g. export PATH="$PATH:/home/player/.local/bin"
### Setup AWS S3 bucket
* In S3, create a new backup bucket. You may wish to set it up with versioning and lifecycle management rules so that you can just keep pushing to the same object and old versions will be deleted and/or moved to Glacier. Also recommended to establish tags and logging if cost is likely to be significant and therefore should be tracked.
* In IAM, create a programmatic user and ensure it has an access key and secret access key
View gist:187651b7e7a9b3826d32b43ab98ccb85
*Places Geek*
Unusual places
https://en.wikipedia.org/wiki/Point_Roberts,_Washington - US coastal enclave in Canada
https://en.wikipedia.org/wiki/Dahala_Khagrabari - Triple enclave until 2015 (Indian enclave inside Bangladeshi enclave inside Indian enclave inside Bangladesh)
http://www.paulplowman.com/stuff/house-address-twins-proximity/ - UK house address twins, including 2 Manchester houses beside each other with same address
@mahemoff
mahemoff / itunes-categories.md
Last active Aug 20, 2017
iTunes categories for programming podcasts
View itunes-categories.md

iTunes categories in most popular feeds at https://player.fm/featured/programming

Technology
Technology,Tech News,Technology,Software How-To
Technology
Technology,Software How-To
Technology,Tech News,Technology,Software How-To
Technology
Technology,Tech News,Education,Education Technology,Technology,Software How-To
View Ruby random string performance
# ruby 2.3.1p112 MacOS on MBP Retina late 2013
# Benchmarking some techniques at:
# https://stackoverflow.com/questions/12911869/is-there-a-faster-way-to-generate-random-string-in-ruby
# https://stackoverflow.com/questions/88311/how-to-generate-a-random-string-in-ruby
# Results show Object.hash is easily the fastest and shuffle is the slowest (as well as not being great as it doesn't support repeating characters)
# SecureRandom is a good compromise, especially if the string is needed for security purposes. It's 5 tims slower than Object.hash, but Object.hash
# is an int that would need converting to string to make an equivalent, smaller, representation.
[35] pry(main)> all=[]; Benchmark.measure { 10000.times { all << ('a'..'z').to_a.shuffle[0,8].join} }
View mysql-backup-for-replication.md

Put database in read-only mode and capture master log position:

mysqL> FLUSH TABLES WITH READ LOCK; SET GLOBAL read_only = ON; SHOW MASTER STATUS;`

Copy entire mysql data folder:

bash> cp -r /var/lib/mysql /home/me/prod_varlibmysql20170715 ; date`

When copy is complete, immediately turn off read-only mode:

View linode-plans.txt
[<Linode api_id=499946, label='psaa'>]
[ { u'AVAIL': { u'10': 500,
u'11': 500,
u'2': 500,
u'3': 500,
u'4': 500,
u'6': 500,
u'7': 500,
u'8': 500,
u'9': 500},
@mahemoff
mahemoff / long-processes.md
Created Jun 28, 2017
Show long-running processes
View long-processes.md

The following MySQL command will show you long-running processes (exceeding 5 seconds in this case).

select * from information_schema.processlist where command <> 'sleep' and time > 5;

You can run it from console to view those happening now, or you could make a script to poll it periodically, with something like:

echo "select * from information_schema.processlist where command <> 'sleep' and time > 5;" | mysql > long-running.log

(See also https://serverfault.com/questions/416380/log-slow-queries-killed-before-completion/858093)

@mahemoff
mahemoff / sidekiq_utils.rb
Created Jun 12, 2017
Sidekiq Utils for make simplify your debugging
View sidekiq_utils.rb
Class SidekiqUtils
def self.queues
::Sidekiq::Stats.new.queues.keys.map { |name| ::Sidekiq::Queue.new(name) }
end
def self.find_queue(name)
self.queues.find { |q| q.name==name.to_s }
end
You can’t perform that action at this time.