Skip to content

Instantly share code, notes, and snippets.

View glebm's full-sized avatar

Gleb Mazovetskiy glebm

View GitHub Profile
@glebm
glebm / object_enumerable.rb
Last active August 29, 2015 14:00
make all Ruby things Enumerable
class Object
def each(&block)
return to_enum(:each) { 1 } unless block
[self].each(&block)
end
include Enumerable
end
class NilClass
def each(&block)
@simeonwillbanks
simeonwillbanks / Gemfile
Created January 26, 2012 23:18
#gemfile rails 3, rspec-rails, capybara, capybara-webkit, headless in order to run request specs that can test javascript
source 'https://rubygems.org'
gem 'rails', '3.2.0'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3'
@rbin
rbin / scss2sass.sh
Created January 30, 2013 02:29
Look for any SCSS files in a Directory, and change them to minimal-style .sass! (The better version!
#!/bin/bash
for f in *.scss; do sass-convert $f ${f%scss}sass ; done
rm *.scss
@steveklabnik
steveklabnik / fetch_gists.rb
Last active December 15, 2015 15:29
Fetch Gists from the API
require 'net/http'
require 'json'
# a simple wrapper to do an HTTP GET
def fetch_uri(uri)
Net::HTTP.get_response(URI(uri))
end
# GETs the URI and returns a Ruby hash.
def fetch_json(uri)
@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'
@thinkerbot
thinkerbot / README.md
Created May 7, 2012 02:06
A shell script transpiler

Provides a mechanism to write portable shell scripts in a higher-level language.

Ruby may be used to describe shell scripts in code. For example shell commands may be represented as methods and command pipelines as method chains. The method calls are translated into shell script. Zero or more script files may be generated in this process.

Cursor objects can be used to mark the locations in the final script where a given shell expression is to be added. For example one cursor could mark where options are defined in a 'getopts' command, another could mark where the option

@jonwolfe
jonwolfe / gist:7897610
Created December 10, 2013 20:22
This is how we use Google Analytics with Turbolinks. I put this in a analytics.js.coffee file and require it after turbolinks. That's it. Works on browsers that support Turbolinks and those that don't. Also works with parts of your app that may not use Turbolinks. If you need to record pageviews manually for any reason, just call GoogleAnalytics…
class @GoogleAnalytics
@load: ->
# Google Analytics depends on a global _gaq array. window is the global scope.
window._gaq = []
window._gaq.push ["_setAccount", GoogleAnalytics.analyticsId()]
# Create a script element and insert it in the DOM
ga = document.createElement("script")
ga.type = "text/javascript"
@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 / 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 / RenderWhitespace.md
Last active September 26, 2017 11:17
Render whitespace on GitHub