Skip to content

Instantly share code, notes, and snippets.

View niedfelj's full-sized avatar

Joel N niedfelj

View GitHub Profile
@niedfelj
niedfelj / initializer.rb
Created March 10, 2017 14:17 — forked from bradgessler/initializer.rb
MIddleware for making legacy versions of Internet Explorer (anything below 11) work with rails. I release this code under MIT license.
# ./config/initializers/rewrite_ie_header.rb
# Don't forget to include the middleware file! If you have a ./lib/middleware folder in rails
# a `require './lib/middleware/rewrite_ie_header.rb'` should do the trick
#
# IE has a really stupid accept header, so here we scope its domain of mime-types that it can negotiate, otherwise we'll
# end up with weird bugs where if you hit /mcp/:id, IE will download a .ppt file instead of the .html content.
#
# Issue documented in more detail at https://github.com/rails/rails/issues/9940.
Rails.application.config.middleware.use RewriteIEAcceptHeader do |ie_mime_types|
@niedfelj
niedfelj / gtk-firefox.sh
Created November 17, 2016 19:43 — forked from joekiller/gtk-firefox.sh
INSTALL FIREFOX ON AMAZON LINUX X86_64 COMPILING GTK+
#!/bin/bash
# GTK+ and Firefox for Amazon Linux
# Written by Joseph Lawson 2012-06-03
# http://joekiller.com
# http://joekiller.com/2012/06/03/install-firefox-on-amazon-linux-x86_64-compiling-gtk/
# chmod 755 ./gtk-firefox.sh
# sudo ./gtk-firefox.sh
@niedfelj
niedfelj / headless.md
Created November 15, 2016 20:21 — forked from addyosmani/headless.md
So, you want to run Chrome headless.
@niedfelj
niedfelj / test-three.py
Created November 15, 2016 20:19 — forked from miohtama/test-three.py
Testing Three.js 3d rendered with Selenium + Python
"""
See that rendering Javascript loads jobs properly.
Skeleton based on https://github.com/Pylons/deformdemo/blob/master/deformdemo/test.py
Running::
./run-selenium.sh
@niedfelj
niedfelj / gist:01427d5bfb3436dbbe364a0415b2b5e4
Created July 19, 2016 14:20 — forked from rakasaka/gist:1169341
Unsupervised topic modeling in Ruby using LDA
require 'lda-ruby'
corpus = Lda::Corpus.new
corpus.add_document(Lda::TextDocument.new(corpus, "a lion is a wild feline animal", []))
corpus.add_document(Lda::TextDocument.new(corpus, "a dog is a friendly animal", []))
corpus.add_document(Lda::TextDocument.new(corpus, "a cat is a feline animal", []))
lda = Lda::Lda.new(corpus)
lda.verbose = false
lda.num_topics = (2)
lda.em('random')
@niedfelj
niedfelj / decode_session_cookie.rb
Created March 23, 2016 15:38 — forked from pdfrod/decode_session_cookie.rb
A simple script to decode Rails 4 session cookies
var elasticsearch = require('elasticsearch');
var client = new elasticsearch.Client();
var eventPattern = /([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) \"(.*?)\" \"(.*?)\" \"(.*?)\" \"(.*?)\" \"(.*?)\"/;
exports.handler = function(data, context) {
var events = [];
var encodedEvent, rawEvent,
matchedEvent, event, i,
commands;

Instrument Anything in Rails 3

With Rails 3.0 released a few weeks ago I've migrated a few apps and I'm constantly finding useful new improvements. One such improvement is the ability to log anything in the same way that Rails internally logs ActiveRecord and ActionView. By default Rails 3 logs look slightly spiffier than those produced by Rails 2.3: (notice the second line has been cleaned up)

Started GET "/" for 127.0.0.1 at Mon Sep 06 01:07:11 -0400 2010
  Processing by HomeController#index as HTML
  User Load (0.2ms)  SELECT `users`.* FROM `users` WHERE (`users`.`id` = 3) LIMIT 1
  CACHE (0.0ms)  SELECT `users`.* FROM `users` WHERE (`users`.`id` = 3) LIMIT 1

Rendered layouts/_nav.html.erb (363.4ms)

module Moped
module Instrumentation
def self.instrument(klass)
klass.class_eval do
def logging(operations)
instrument_start = (logger = Moped.logger) && logger.debug? && Time.new
yield
ensure
instrument_end = 1000 * (Time.new.to_f - instrument_start.to_f)
# Add `gem 'heroku-api', :git => 'https://github.com/heroku/heroku.rb.git'` to your Gemfile
# Set the APP_NAME environment variable to the name of the Heroku app you wish to control.
# Set the HEROKU_API_KEY environment variable to the API key found on the Heroku 'My Account' page.
# You can now create a scheduler instance that runs `bundle exec rake heroku:web:restart` to automate
# restarting workers. The task will select a different web instance every 10 minutes, based on the number of instances that are running.
namespace :heroku
namespace :web do
task :restart do