Skip to content

Instantly share code, notes, and snippets.

View glebm's full-sized avatar

Gleb Mazovetskiy glebm

View GitHub Profile
@glebm
glebm / generate.js
Last active October 24, 2017 18:57
A quick hack to generate a codepoint set presence condition (JS)
const regenerate = require('regenerate');
/* char-graphic? */
const SETS = ['Letter', 'Mark', 'Number', 'Punctuation', 'Symbol'].map(category =>
require(`unicode-10.0.0/General_Category/${category}/code-points.js`));
/* char-blank? */
// const SETS = [['\t']].concat(['Space_Separator'].map(category =>
// require(`unicode-10.0.0/General_Category/${category}/code-points.js`)));
@glebm
glebm / RenderWhitespace.md
Last active September 26, 2017 11:17
Render whitespace on GitHub
@glebm
glebm / rainbows.production.conf
Created October 24, 2012 15:57
Example Rainbows Config
# -*- encoding : utf-8 -*-
#= Rainbows HTTP server (on unix socket!)
#== Rainbows can be used to manage multiple forked workers in a specified concurrency-IO model
# Set working directory for Capistrano
# pwd -L keeps symlinks
working_directory `pwd -L`.chomp
# Listen through a unix socket
@glebm
glebm / TextPlainStyleDarkCentered.md
Last active September 14, 2017 14:35
Light on dark centered content style for text/plain documents

This is a userscript with a light-on-dark content-centered style for plain/text documents.

light-on-dark-plain-text

Installation

To install this userscript in Chrome, save the JavaScript file and drag it onto the chrome://extensions page.

If you use ViolentMonkey, TamperMonkey, or GreaseMonkey, install from one of these links:

@glebm
glebm / async_emails_i18n.rb
Last active August 8, 2017 09:42
Inject locale into Resque::Mailer and Devise::Async
require 'resque_mailer'
require 'devise/async'
# pop and set locale from the args before running
module PerformWithLocale
def perform(*args)
I18n.with_locale(args.pop) do
super(*args)
end
end
@glebm
glebm / dependencies_logger.rb
Created November 20, 2016 07:50
A logger for ActiveSupport::Dependencies
# Place this file into lib/dependencies_logger.rb and require it from application.rb after Bundler.require as:
# require_relative '../lib/dependencies_logger'
require 'active_support/dependencies'
class DependenciesLogger
def initialize
@need_newline = false
@load_depth = 0
end
@glebm
glebm / cloud_front.rb
Created September 24, 2011 13:28
A module to invalidate cache on Amazon CloudFront
require 'openssl'
require 'net/http'
require 'net/https'
module CloudFront
extend self
def invalidate(path)
date = Time.now.utc
date = date.strftime("%a, %d %b %Y %H:%M:%S %Z")
@glebm
glebm / console.log
Created August 12, 2016 09:24
Thredded #352 failure log
User tracking what they have and have not already read
D, [2016-08-12T09:16:45.975024 #5152] DEBUG -- :  (0.1ms) BEGIN
D, [2016-08-12T09:16:45.975303 #5152] DEBUG -- :  (0.2ms) COMMIT
D, [2016-08-12T09:16:45.975575 #5152] DEBUG -- :  (0.1ms) BEGIN
D, [2016-08-12T09:16:45.977178 #5152] DEBUG -- :  (0.2ms) SAVEPOINT active_record_1
D, [2016-08-12T09:16:45.978641 #5152] DEBUG -- : SQL (0.3ms) INSERT INTO "users" ("email", "name", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id" [["email", "user220@example.com"], ["name", "Dr. Ellis O'Keefe"], ["created_at", "2016-08-12 09:16:45.977492"], ["updated_at", "2016-08-12 09:16:45.977492"]]
D, [2016-08-12T09:16:45.979315 #5152] DEBUG -- :  (0.2ms) RELEASE SAVEPOINT active_record_1
D, [2016-08-12T09:16:45.980593 #5152] DEBUG -- :  (0.1ms) SAVEPOINT active_record_1
D, [2016-08-12T09:16:45.982087 #5152] DEBUG -- : [1
@glebm
glebm / i18_status_controller.rb
Last active December 25, 2015 00:19
i18n-tasks html report example
require 'i18n/tasks/base_task'
...
def i18n_status
task = I18n::Tasks::BaseTask.new
@missing = task.missing_keys
@unused = task.unused_keys
end
...
@glebm
glebm / md-hl-code
Created September 9, 2013 20:50
Convert all markdown code blocks from indented to the syntax-highlighted ``` blocks
#!/usr/bin/env ruby
def convert(lang, md)
md.gsub(/\t/, ' ' * 4).gsub(/((?:^\s{4}[^\n]*\n)+)/) {
"\n```#{lang}#{$1.gsub(/^[ ]{4}/, '')}```\n"
}
end
argv = ARGV.dup
path = argv.pop or raise 'pass path'