Skip to content

Instantly share code, notes, and snippets.

✘  ~  cat .config/systemd/user/swayidle.service
[Unit]
Description=Idle manager for Wayland
Documentation=man:swayidle(1)
PartOf=graphical-session.target
[Service]
Type=simple
ExecStart=/usr/bin/swayidle -w \
timeout 900 'swaymsg "output * dpms off"' \
@jwhiting
jwhiting / warmup.rb
Created May 14, 2018 22:00
Warming up EBS volumes on RDS replicas/snapshots (ruby script)
#!/usr/bin/env ruby
require 'pg'
=begin
when creating a postgres db replica in RDS, or restoring from a snapshot, the
underlying EBS volume of the new instance must be initialized by reading every
block, otherwise the blocks will be lazy-initialized by production queries
which will be extremely latent. (i've seen normally 50ms queries take 30s in
@abepark01
abepark01 / install-mongodb-2.6.12-from-tarball.sh
Created November 16, 2017 20:42
install mongodb-2.6.12 from the tarball
#!/usr/bin/env bash
# run this script from your home folder
# sudo bash
curl -O http://downloads.mongodb.org/linux/mongodb-linux-x86_64-2.6.12.tgz
tar -zxvf mongodb-linux-x86_64-2.6.12.tgz
cp mongodb-linux-x86_64-2.6.12/bin/* /usr/local/bin
groupadd mongodb
useradd --system --no-create-home -g mongodb mongodb
@kilhage
kilhage / nginx-gzip.conf
Created December 4, 2015 11:07
Enables gzip compression for common mime types in nginx
# most people include something like this. don't.
# check your default nginx.conf, it's already covered in a much better way.
#gzip_disable "MSIE [1-6]\.(?!.*SV1)";
# compress proxied requests too.
# it doesn't actually matter if the request is proxied, we still want it compressed.
gzip_proxied any;
# a pretty comprehensive list of content mime types that we want to compress
# there's a lot of repetition here because different applications might use different
@ippeiukai
ippeiukai / sequel_each_in_batches.rb
Last active March 26, 2024 16:01
ActiveRecord's find_each and find_in_batches ported to Sequel. Sequel's paged_each is not practical when converting large data due to its use of transaction and offset. (Special thanks to @nomuson for working out the primary_keys_expr logic together.)
# ActiveRecord's find_each and find_in_batches ported to Sequel.
# Sequel's paged_each is not practical when converting large data due to its use of transaction and offset.
#
# Usage:
#
# SequelEachInBatches.find_each(dataset, keys) { |record| ... }
#
# It can also monkey patch Sequel::Dataset:
#
# Sequel::Dataset.send(:include, SequelEachInBatches)
@jj1bdx
jj1bdx / sleep5.sh
Created June 2, 2014 04:02
A shell one-liner for an infinite loop (sh/zsh/bash compatible)
while true; do date; sleep 5; done
@pithyless
pithyless / integer.rb
Created March 24, 2014 10:50
Ruby Integer::MAX and Integer::MIN
class Integer
N_BYTES = [42].pack('i').size
N_BITS = N_BYTES * 16
MAX = 2 ** (N_BITS - 2) - 1
MIN = -MAX - 1
end
p Integer::MAX #=> 4611686018427387903
p Integer::MAX.class #=> Fixnum
p (Integer::MAX + 1).class #=> Bignum
@szabcsee
szabcsee / data2csv-data2json-data2arr.rb
Last active December 1, 2020 00:10
Sinatra delivers data as json and deliver data in csv as attachment
require 'sinatra'
require 'json'
require 'csv'
# Serve data as JSON
get '/hi/:name' do
name = params[:name]
content_type :json
{ :message => name }.to_json
end
@colinsurprenant
colinsurprenant / closure_invocation.rb
Created June 26, 2013 17:53
benchmarks for 3 different ways to dynamically invoke a closure in an instance context
require 'benchmark'
class DSL1
def initialize
@i = 1
end
def self.register(&block)
@block = block
@quiver
quiver / README.md
Last active April 3, 2024 15:47
Who says PostgreSQL can't Pub/Sub like Redis?

Pub/Sub pattern with PostgreSQL's LISTEN/NOTIFY command

This is a simple chat-like program using pub-sub pattern, backed by PostgreSQL's LISTEN/NOTIFY command.

Publish

publish message to foo channel from user nickname.

$ python pub.py foo nickname
PUBLISH to channel #foo