Skip to content

Instantly share code, notes, and snippets.

View bxt's full-sized avatar

Bernhard Häussner bxt

View GitHub Profile
@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 / 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 / #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 / 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 / .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
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 / higher-order-functions.js
Created February 4, 2015 02:41
Higher order functions chain (compose) and accessor for JS, highly useful for d3.js
function acc(i) {
return function(d) {
return d[i];
}
}
function ch(a,b) {
return function(d) {
return a(b(d));
}
@bxt
bxt / start-urxvt.sh
Last active September 22, 2015 10:22 — forked from anonymous/start-urxvt.sh
Starting urxvt with nice colors, size and position
urxvt -depth 32 -bg rgba:ff00/f900/db00/dddd -bd rgba:ff00/f800/d000/dddd -fg rgba:0000/0000/0000/eeee -sr -scrollstyle plain -geometry 140x37+$[ 50 + $[ RANDOM % 100 ]]+$[ 500 + $[ RANDOM % 200 ]]
@bxt
bxt / git-deletebranches.sh
Last active June 23, 2021 15:01
Git Delete Merged Branches
#!/bin/bash
MAIN=${1:-development}
BRANCHES=$(git branch --merged $MAIN | grep -v -e 'master\|staging\|development\|\*')
echo Branches merged into $MAIN:
echo $BRANCHES
read -p "Delete these branches (y/n)? " answer
@bxt
bxt / say.sh
Last active August 8, 2017 09:46
# Test all the voices:
say -v '?' | awk '{ print($0); c1="say -v "$1" "; $1=""; $2=""; $3=""; c=c1 "\"" $0 "\""; system(c); }'
# Test the english voices only:
say -v '?' | awk '/en_US/{ print($0); c1="say -v "$1" "; $1=""; $2=""; $3=""; c=c1 "\"" $0 "\""; system(c); }'
# Test the international voices:
say -v '?' | awk '!/en_US/{ print($0); c1="say -v "$1" "; $1=""; $2=""; $3=""; c=c1 "\"" $0 "\""; system(c); }'
# Creepy: