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 / mysql.sh
Last active Oct 6, 2019
circleci mysql upgrade
View mysql.sh
#!/bin/bash
set -x
set -e
export DEBIAN_FRONTEND=noninteractive
sudo apt-get --purge autoremove -y mysql-server-5.6
curl -LO https://dev.mysql.com/get/mysql-apt-config_0.7.3-1_all.deb
echo mysql-apt-config mysql-apt-config/select-product select Apply | sudo debconf-set-selections
@mahemoff
mahemoff / names.txt
Created Apr 5, 2012
Reserved username list
View names.txt
###
A meta-compilation of:
https://raw.github.com/gist/1453705/d253733a56632a8d2c29321a75c18b627fa4dda8/reserved_usernames.rb
http://blog.postbit.com/reserved-username-list.html
http://www.quora.com/How-do-sites-prevent-vanity-URLs-from-colliding-with-future-features
(Took out some company-specific terms at the top of the first one (e.g. imulus, stacks), added one term so far - 'edits'.)
NOTE: Does not include profanities. You may or may not want to add a list of those.
(See https://www.google.com/search?q=profanity+list, but don't try to apply regexp's here because Scunthorpe - http://en.wikipedia.org/wiki/Scunthorpe_problem)
@mahemoff
mahemoff / Ansible Disk Check
Last active Sep 6, 2019
Show disk space and warn about disk full in Ansible
View Ansible Disk Check
* Shows a message while asserting like:
ok: [host] => {
"msg": "disk usage 4.2B of total 20.0GB (21.0%) (should be within limit 90.0%)"
}
* Note this only looks at first mount point on current node
* Fails if disk is near-full
* Last step pushes to a push-based monitoring service, which will alert us if it doesn't get there after some time
* Need to setup a variable `disk_limit`, which is the max acceptable usage ratio, e.g. set it to 0.8 if you want to keep disks within 80% of max size
@mahemoff
mahemoff / bench.rb
Last active Sep 6, 2019
in versus include
View bench.rb
#!/usr/bin/env ruby
require 'benchmark'
require 'active_support/all'
puts 'in', Benchmark.measure { 90000.in?(1..99000)}
puts 'include', Benchmark.measure { (1..99000).include? 90000 }
View video-client.html
<!-- This is a Node+WebSocket powered demo to sync videos
across different browsers. This file is the client,
the other one is the Node server. Powered by Node and
http://github.com/miksago/node-websocket-server -->
<style>
.inactive { display: none; }
.active { display: block; }
</style>
<script>
@mahemoff
mahemoff / parallel_array.rb
Created Jun 29, 2019
Extending Array with Parallel gem
View parallel_array.rb
class Array
%w(each map each_with_index map_with_index flat_map any? all?).each { |meth|
define_method("#{meth}_in_parallel") { |&block|
Parallel.send(meth, self) { |item| block.call(item) }
}
}
}
@mahemoff
mahemoff / async-widget-load.html
Created Feb 16, 2015
async freshdesk widget load (general technique for any lib without explicit async support)
View async-widget-load.html
<script src="https://s3.amazonaws.com/assets.freshdesk.com/widget/freshwidget.j
s" async='async'></script>
<script>
(function() {
var freshTriesRemaining = 12;
setTimeout(function() {
if (typeof(FreshWidget)!='undefined')
FreshWidget.init(...);
else if (freshTriesRemaining-- > 0)
setTimeout(arguments.callee, 250);
@mahemoff
mahemoff / application_controller.rb
Created Apr 9, 2015
Cloudflare country detection (geo-ip) in Ruby/Rails
View application_controller.rb
class ApplicationController < ActionController::Base
def cloudflare_country_code
request.headers['HTTP_CF_IPCOUNTRY']
end
def eu_request?
cloudflare_country_code.in? %w(GB FR DE ..... )
end
@mahemoff
mahemoff / uniq.rb
Created Sep 12, 2014
Ensure Sidekiq jobs are unique (if the queue contains several jobs with same class and args, this will delete all but one of them)
View uniq.rb
def self.uniq! queue_name
seen_already = Set.new
Sidekiq::Queue.new(queue_name).each { |job|
key = { job.klass => job.args }
key.in?(seen_already) ? job.delete : seen_already << key
}
end
You can’t perform that action at this time.