Skip to content

Instantly share code, notes, and snippets.

View leh's full-sized avatar

Daniel Lehmann leh

  • Taktsoft
  • Bonn / Germany
View GitHub Profile
(function(){
// This snippet is a customized version of the code found on
// stackoverflow. Since firefox only copies to the clipboard when the event
// was triggered by a user, I had to add the button to the top of the page.
// In chrome it might work without the need for a button, directly from a
// bookmarklet. See the following for more information.
// https://stackoverflow.com/questions/400212/how-do-i-copy-to-the-clipboard-in-javascript?page=1&tab=votes#tab-top
// To create a bookmarklet you might want to use the following:
// https://www.yourjs.com/bookmarklet/
@njakobsen
njakobsen / live_database_dump.rb
Last active November 5, 2021 02:28
Live stream a database dump (or any other STDOUT) using Rails 4. Why would you want this? If you have a large database dump and want to avoid storing it in memory as Rails streams it. This allows pipe the dump directly into the http response instead of storing it as a file, sending it, and then deleting it. Let me know what you think! I've teste…
class DatabaseController < ApplicationController
def database_dump
database = Rails.configuration.database_configuration[Rails.env]["database"]
send_file_headers!(:type => 'application/octet-stream', :filename => "#{database}_#{Time.now.to_s(:human)}.backup")
pipe = IO.popen("pg_dump '#{database}' -F c")
stream = response.stream
while (line = pipe.gets)
stream.write line
sleep 0.0001 # HACK: Prevent server instance from sleeping forever if client disconnects during download
@leh
leh / key_swapper.py
Created November 22, 2012 20:06
This python script allows you to change the unity/gnome keyboard settings for swapping the meta (windows) and alt keys. Should work with Python 2.7 and 3.2
#!/usr/bin/python
# This python script allows you to change the unity/gnome keyboard
# settings for swapping the meta (windows) and alt keys. Should work with
# Python 2.7 and 3.2
from gi.repository import Gio
class KeySwapper:
SWAP_ALT_WIN='altwin\taltwin:swap_lalt_lwin'
$ rvm install jruby
jruby-1.6.7.2 - #downloading jruby-bin-1.6.7.2, this may take a while depending on your connection...
jruby-1.6.7.2 - #extracting jruby-bin-1.6.7.2 to /Users/tony/.rvm/src/jruby-1.6.7.2
jruby-1.6.7.2 - #extracted to /Users/tony/.rvm/src/jruby-1.6.7.2
jruby-1.6.7.2 - #nailgun
Error running 'jruby_install_build_nailgun', please read /Users/tony/.rvm/log/jruby-1.6.7.2/nailgun.log
@leh
leh / whiny_attr_accessible.rb
Created September 1, 2011 08:58
Makes attr_accessible whiny. A monkey patch for Rails 3.1 to raise an exception instead of a warning in the logs when protected fields are mass assigned
# Rails edge includes pluggable sanitizers for mass assignment. Really cool is the
# StrictSanitizer which raises an exception instead of a log message, which makes
# problems easier to spot in development.
# For the time being, there seems to be no way to achieve this in Rails 3.1 via
# configuration. Monkey patching to the rescue!
# Copy the gist into config/initializers and configure the environments in which the
# exception gets raised.
if ['development', 'test'].include?(Rails.env)
ActiveModel::MassAssignmentSecurity::BlackList.class_eval do
@erotte
erotte / server_setup.md
Created July 26, 2011 20:04
Server Setup Ubuntu 10.4/rvm/nginx/passenger Hosteurope VM

Server Setup

Unsere Setup-Routine für eine Rails-App mit Nginx, Passenger, rvm auf einen Host Europe-VPS mit Ubuntu 10.4.

Installation der benötigten Pakete

apt-get update

apt-get install -y build-essential bison openssl libreadline5 libreadline5-dev curl \