Skip to content

Instantly share code, notes, and snippets.

Wojciech Wnętrzak morgoth

View GitHub Profile
@morgoth
morgoth / polymorphic_eagerload.rb
Created Feb 24, 2014
rails 4.1 cannot eager load polymorphic associations
View polymorphic_eagerload.rb
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)
View index.html
<!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;
View multi_xml_bug.rb
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 Jul 10, 2012
Layout filter for rake-pipeline
View layout_filter.rb
# 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
Downloads PRO Railscasts using your private RSS feed
View railscasts.rb
# 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 Jan 27, 2012
Rake task to copy local files to remote server via FTP
View deployer.rake
# 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 Dec 16, 2011
Transmission daemon configuration
View gist:1486932
# 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 Sep 28, 2015
Pulseaudio sound server configuration
View gist:1468756
# 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 Aug 22, 2011
Init script for Peergroup node server
View gist:1162135
#! /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
View gist:822127
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
You can’t perform that action at this time.