Skip to content

Instantly share code, notes, and snippets.

View morgoth's full-sized avatar

Wojciech Wnętrzak morgoth

View GitHub Profile
@morgoth
morgoth / polymorphic_eagerload.rb
Created February 24, 2014 10:02
rails 4.1 cannot eager load polymorphic associations
gem 'activerecord', '4.1.0.rc1'
# gem 'activerecord', '4.0.2'
require 'active_record'
require 'minitest/autorun'
require 'logger'
puts ActiveRecord::VERSION::STRING
ActiveRecord::Base.logger = Logger.new(STDOUT)
@morgoth
morgoth / index.html
Created August 8, 2013 18:34
via:geojson.io
<!DOCTYPE html>
<html>
<head>
<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no' />
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
.marker-properties {
border-collapse:collapse;
require "multi_xml"
# copy paste above xml document to `xml` variable
MultiXml.parser
# => MultiXml::Parsers::Ox
MultiXml.parse(xml).keys
# => ["aws:UrlInfoResponse"]
MultiXml.parser = :rexml
# => :rexml
MultiXml.parse(xml).keys
@morgoth
morgoth / layout_filter.rb
Created July 10, 2012 18:29
Layout filter for rake-pipeline
# Support for rendering views in layout
# Example usage in Assetfile:
#
# match "views/*.md" do
# markdown
# layout path: "app/views/layout.erb"
# concat { |input| input.sub(%r{views/}, "").sub(/\.md/, ".html") }
# end
require "rake-pipeline"
@morgoth
morgoth / railscasts.rb
Created May 28, 2012 12:14
Downloads PRO Railscasts using your private RSS feed
# Downloads PRO Railscasts
# Your private feed url can be found on https://railscasts.com/subscriptions/current
require "multi_xml"
require "open-uri"
PRIVATE_RSS_URL = "private-url"
PUBLIC_RSS_URL = "http://feeds.feedburner.com/railscasts"
private_feed = MultiXml.parse open(PRIVATE_RSS_URL)
@morgoth
morgoth / deployer.rake
Created January 27, 2012 20:03
Rake task to copy local files to remote server via FTP
# Rake task to copy local files to remote server via FTP
# required credentials.yml file, that contains keys:
# server, username, password
require "net/ftp"
require "yaml"
class FTPClient
attr_reader :remote_path
@morgoth
morgoth / gist:1486932
Created December 16, 2011 17:09
Transmission daemon configuration
# Tested on Ubuntu 11.10
# sudo apt-get install transmission-daemon
# Customize /etc/transmission-daemon/settings.json
{
"alt-speed-down": 50,
"alt-speed-enabled": false,
"alt-speed-time-begin": 540,
"alt-speed-time-day": 127,
"alt-speed-time-enabled": false,
"alt-speed-time-end": 1020,
@morgoth
morgoth / gist:1468756
Last active September 28, 2015 16:58
Pulseaudio sound server configuration
# Configuring sound server
# Tested on Ubuntu 11.10
sudo apt-get install pulseaudio-module-zeroconf
# Change /etc/default/pulseaudio file on server to contain:
PULSEAUDIO_SYSTEM_START=1
DISALLOW_MODULE_LOADING=1
@morgoth
morgoth / gist:1162135
Created August 22, 2011 10:54
Init script for Peergroup node server
#! /bin/sh
### BEGIN INIT INFO
# Provides: node_debian_init
# Required-Start: $remote_fs $named $syslog
# Required-Stop: $remote_fs $named $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: DEBIAN initscript for node.js servers/apps
# Description: ex : proxy server is a node.js http server listening on
def respond_with(*resources, &block)
raise "In order to use respond_with, first you need to declare the formats your " <<
"controller responds to in the class level" if self.class.mimes_for_respond_to.empty?
if response = retrieve_response_from_mimes(&block)
options = resources.size == 1 ? {} : resources.extract_options!
resources = resources.size == 1 ? Array.wrap(resources.first) : resources
options.merge!(:default_response => response)
(options.delete(:responder) || self.class.responder).call(self, resources, options)
end