Skip to content

Instantly share code, notes, and snippets.

View bxt's full-sized avatar

Bernhard Häussner bxt

View GitHub Profile
class SwitchTypeOfStateToEnum < ActiveRecord::Migration
class Order < ActiveRecord::Base
enum state: [ :pending, :running, :success, :failed ]
end
def change
rename_column :orders, :state, :state_old
add_column :orders, :state, :integer
reversible do |dir|
@bxt
bxt / .htaccess
Created November 26, 2014 17:35
Simple .htaccess file
<Files ~ "^\.(htaccess|htpasswd)$">
deny from all
</Files>
Options Indexes
AuthUserFile /etc/apache2/.htpasswd
AuthGroupFile /dev/null
AuthName "Temporarily blocked! Please contact your webmaster"
AuthType Basic
require valid-user
order deny,allow
@bxt
bxt / hash_building.rb
Last active August 29, 2015 14:02
Building a hash in Ruby
# These three do the same thing:
[:type, :action].each_with_object({}) {|m,h| h[m] = order.send(m)}
[:type, :action].inject({}) {|h,m| h[m] = order.send(m); h}
Hash[[:type, :action].map {|m| [m, order.send(m)]}]
@bxt
bxt / #SQL-Window-Functions-README.md
Last active August 29, 2015 14:00
SQL Window Functions Example Code

SQL Window Functions Example Code

This gist will contain some example code using SQL window functions. The code is made for PostgreSQL 9.1.9 and may or may not be compatible to other databases. MySQL is certainly not supported as it currently (2014) lacks support for window functions alltogether. The code creates, modifies and deletes some tables (see 05_cleanup.sql), so make sure to run it in a fresh db if you are not sure this does not mess with your existing data.

@bxt
bxt / build-coffeescript.sh
Last active August 29, 2015 14:00
Build coffeescript file
#!/bin/bash
if [ $# -ne 1 ]; then
echo "Usage: $(basename $0) COFFEEFILE"
echo " - Compile COFFEEFILE into a minified javascript on file changes."
exit 64
fi
COFFEE=coffee
UGLIFYJS=uglifyjs
@bxt
bxt / merge_git_repos.md
Last active January 29, 2018 18:26
Git: Merge other repository into subfolder

Copy the child repo to your /tmp (Or into another ramdisk, should be faster)

cd into the new repo.

Now lets rewirte stuff.

Move into subdirectory (here called "report"):

git filter-branch --index-filter \

'git ls-files -s | sed "s-$(printf '''\t''')"*-&report/-" |

@bxt
bxt / sinuosity.md
Created March 14, 2014 20:59
Rivier sinuosity

Nile. Length: 6852 km. Linear: 3700 km. Sinuosity: 1.85. Amazon. Length: 6448 km. Linear: 3000 km. Sinuosity: 2.15.

@bxt
bxt / java-problems.md
Last active December 30, 2015 16:59
Java Problems

Problems with the Language Java (7)

This is my "I love Java, but..." document. And now follows some ranting about Java:

Constructor Rules

super() must be the first statement in the constructor. This is just nonsense, as you can work around this and add more statements by calling methods on the parameters to super(). Thus, all checks involving use of this must be implemented in the compiler anyways.

@bxt
bxt / setup_osx.md
Last active June 24, 2024 06:31
Setup macOS / OS X so that is does not suck quite that hard (living doc)

Setting up OS X macOS

Things to configure

  • Install latest software update
  • Enable touch ID
  • Make Dock hide and remove some silly apps (photobooth, ...) disable recently used apps
  • Finder:
@bxt
bxt / routes.rb cheatsheet.txt
Created September 9, 2013 12:19
Example code and output for ruby on rails routes
resource :res do
def create_action action = :action
Proc.new {get action}
end
namespace :ns0, &create_action
namespace :nsp, path: "nspp/nsppi", &create_action
namespace :nsf, module: false, &create_action
namespace :nsm, module: :mod, &create_action
scope &create_action(:sco_a)
scope module: 'scm', &create_action(:scm_a)