Skip to content

Instantly share code, notes, and snippets.

Gleb Mazovetskiy glebm

View GitHub Profile
glebm /
Last active Sep 14, 2017
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.



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 / generate.js
Last active Oct 24, 2017
A quick hack to generate a codepoint set presence condition (JS)
View generate.js
const regenerate = require('regenerate');
/* char-graphic? */
const SETS = ['Letter', 'Mark', 'Number', 'Punctuation', 'Symbol'].map(category =>
/* char-blank? */
// const SETS = [['\t']].concat(['Space_Separator'].map(category =>
// require(`unicode-10.0.0/General_Category/${category}/code-points.js`)));
glebm /
Last active Mar 31, 2019
Rails Link Preload Headers

This lets you set the preload headers for your assets, so that the browser can start fetching them before it begins parsing HTML.

glebm /
Last active Oct 12, 2018
Universal Rails async onPageLoad script (Turbolink v2, v5.0, v5.1, jquery-turbolinks, and no Turbolinks)

This lets you load application JavaScript asynchronously from <head>. Compatible with Turbolink v2, v5.0, v5.1, jquery-turbolinks, and no Turbolinks. Compatible with all browsers and IE9+ (only IE10+ will actually benefit from this though).

How to use this:

  1. Add the HTML snippet just before the closing </body> tag.

  2. Add the on_page_load.js script to the beginning of your application.js, and use window.App.onPageLoad(...) instead of document.addEventListener('DOMContentLoaded', ...) and jQuery(($) -> ...) everywhere.

  3. Include your JavaScript like so:

glebm /
Last active Feb 23, 2017
Rust: Erathosthenes prime sieve
fn is_prime(n: usize, primes: &Vec<usize>) -> bool {
for &p in primes {
let q = n / p;
if q < p { return true };
let r = n - q * p;
if r == 0 { return false };
panic!("too few primes")
glebm / dependencies_logger.rb
Created Nov 20, 2016
A logger for ActiveSupport::Dependencies
View dependencies_logger.rb
# 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
glebm / console.log
Created Aug 12, 2016
Thredded #352 failure log
View console.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", ""], ["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 / i18n_status.html.slim
Created Jun 22, 2014
Missing and unused translations report (i18n-tasks v0.5.0+)
View i18n_status.html.slim
h1 Missing and unused translations
- if @missing.present?
.panel-heading: h3.panel-title #{@missing.leaves.count} missing keys
thead: tr
th.text-right Locale
th Key
th Value
glebm / object_enumerable.rb
Last active Aug 29, 2015
make all Ruby things Enumerable
View object_enumerable.rb
class Object
def each(&block)
return to_enum(:each) { 1 } unless block
include Enumerable
class NilClass
def each(&block)
You can’t perform that action at this time.