Skip to content

Instantly share code, notes, and snippets.

View tbuehlmann's full-sized avatar

Tobias Bühlmann tbuehlmann

View GitHub Profile
# config/initializers/draper.rb
Draper::CollectionDecorator.delegate :current_page, :total_pages, :limit_value, :total_count
@tbuehlmann
tbuehlmann / README
Created October 11, 2010 14:15
Installing Ruby 1.9.2-p0 on Ubuntu 10.10 (ubuntu-10.10-desktop-amd64)
$ sudo apt-get install build-essential zlib1g zlib1g-dev libruby1.9.1 libxml2 libxml2-dev libxslt1-dev
$ sudo apt-get build-dep ruby1.9.1
$ wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.2-p0.tar.bz2
$ tar xvjf ruby-1.9.2-p0.tar.bz2
Open ruby-1.9.2-p0/ext/Setup and uncomment the zlib line
$ ./configure
$ make
@tbuehlmann
tbuehlmann / toggle_airplane.rb
Created November 6, 2011 10:23
Android Media volume and speakers issue
Using an HTC Desire (Android 2.2 Froyo), I experienced two weird problems at some time.
1. When listening to music with the default player (didn't try others), I wasn't able to adjust the media volume. The media volume bar moved but the volume actually didn't change. This happened only when earphones/headphones were plugged in.
2. When having a phone call, the phone automagically switched to using the phone speakers. I had to manually switch the speakers off. Each time.
These problems appeared suddenly and were permanent.
I familiarized with the problems since I wasn't able to find a solution. I read about some solutions regarding resetting the phone completely and switching it "off and on again" (seriously…). Tried switching it off and on again, no changes. Didn't try resetting it.
class My::Channel < EM::Channel
attr_accessor :watcher, :logger
def self.create!
channel = new
channel.logger = Logger.new 'sinatra.log'
channel.watcher
channel
end
def watcher
posts = Post.all
ActiveRecord::Associations::Preloader.new.preload(posts, :comments, Comment.where('id > 42'))
@toshimaru
toshimaru / check-server-process-using-jemalloc.rb
Last active February 9, 2024 14:54
Enable jemalloc for alpine.
# Check server process is using jemalloc
# ref. [Japanese] https://tech.studyplus.co.jp/entry/2019/09/09/094140
class AppController < ActionController::Base
def show
r = `strings /proc/#{Process.pid}/maps | grep jemalloc`
render plain: "<h1>#{ENV['LD_PRELOAD'].presence || 'empty'}</h1><pre>#{r}</pre>"
end
end
@barbietunnie
barbietunnie / useful-postgres-commands.md
Last active March 11, 2024 12:19
Postgres Commands

Useful Postgres Commands

1. Determine disk usage of a particular table/database

For a particular table,

SELECT pg_size_pretty( pg_total_relation_size('tablename') );
@raggi
raggi / rack_sse.ru
Last active March 23, 2024 11:10
Rack SSE Example
# rack_sse.ru
#
# An example of basic real-time, single-room broadcast chat using Server Sent
# Events in plain old Rack. This example does NOT use hijack, or the async
# hacks, it just relies on a well implemented threaded Rack server (at time of
# writing this will therefore only work with puma!). Other servers should be
# fixed to support this, as it is pretty critical to how Rack *should* work on
# most servers. The only spec-acceptable failure in this case is not flushing
# the content stream on each yield (for which the rack spec has no workaround
# today).
@jjb
jjb / file.md
Last active April 30, 2024 11:26
Using Jemalloc 5 with Ruby.md

For years, people have been using jemalloc with ruby. There were various benchmarks and discussions. Legend had it that Jemalloc 5 didn't work as well as Jemalloc 3.

Then, one day, hope appeared on the horizon. @wjordan offered a config for Jemalloc 5.

Ubuntu/Debian

FROM ruby:3.1.2-bullseye
RUN apt-get update ; \