Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env ruby
require 'yaml'
require 'active_support/all'
class Hash
def to_hash_recursive
result = self.to_hash
result.each do |key, value|
#!/usr/bin/env ruby
require 'yaml'
require 'active_support/all'
puts ARGV.map{|file| YAML.load_file(file)}.inject(&:deep_merge).to_yaml
@wteuber
wteuber / solidatité.js
Created November 16, 2015 10:16
solidatité
document.body.setAttribute('style', 'margin:0;padding:0;'); document.body.innerHTML = '<body style="margin:0;padding:0;"><div style="width: 100vw;height: 100vh;display: table;"><div style="background: #00f;width: 33%;display: table-cell;"></div><div style="background: #fff;width: 33%;display: table-cell; color: #CCC;text-align:center;vertical-align:middle;font-size: 12vh;">Solidarité</div><div style="background: #f00;width: 33%;display: table-cell;"></div></div></body>';
@wteuber
wteuber / ctrl_enter.js
Created November 16, 2015 14:09
ctrl_enter.js - send forms when pressing crtl+enter instead of only pressing enter
$(document).ready(function() {
$(window).keydown(function(event){
if((event.keyCode == 13 || event.keyCode == 10) && !event.ctrlKey) {
event.preventDefault();
return false;
}
});
});
@wteuber
wteuber / iban_validator.js
Last active January 15, 2016 13:00
IBAN Validator
/*
https://gist.github.com/wteuber/2c481f5f81d2efd39d97
https://jsfiddle.net/f6f2jves/2/
<body>
<input id="iban" type="text" size="30" autofocus><br>
<span id="check">invalid IBAN</span>
</body>
*/
# Ubuntu
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1| sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
# Mac
alert () { osascript -e "display alert \"$1\"" }
class Mysql56 < Formula
desc "Open source relational database management system"
homepage "https://dev.mysql.com/doc/refman/5.6/en/"
url "https://downloads.mariadb.com/archives/mysql-5.6/mysql-5.6.27.tar.gz"
sha256 "8356bba23f3f6c0c2d4806110c41d1c4d6a4b9c50825e11c5be4bbee2b20b71d"
bottle do
sha256 "b2d6eea1c69123f013eb8aecf0947e6c5ee2e13478bc178ec0858754a062bb38" => :el_capitan
sha256 "4395032f58d2222e30fd193b49227d983d3ea3944b7dd1120d2dca1f7d6db3ec" => :yosemite
sha256 "dc0259e2c8707d6975d918b4f35e9129455afabe4577755395bbe1fe3aae8e61" => :mavericks
table = [
{a: 'asd', b: 'asd/asd/sdf/hk/lklkjlkj.lol', c: 'Lorem foo bar baz lol :-)'},
{a: 'aassddaassdd', b: 'asd/lll.lol', c: 'Lorem foo bar baz lol2 :-)'},
{a: 'a', b: 'test/[:id].format', c: ';-)'}]
max_length = -> (k) { [k, table.map { |e| e[k]}.max_by(&:length).length + 3]}
widths = Hash[%i(a b c).map(&max_length)]
# => {:a=>15, :b=>30, :c=>29}
puts table.map{|route| route.map{|key, val| val.ljust(widths[key])}.join}
# asd asd/asd/sdf/hk/lklkjlkj.lol Lorem foo bar baz lol :-)
# aassddaassdd asd/lll.lol Lorem foo bar baz lol2 :-)
@wteuber
wteuber / yaml_cmp.rb
Created September 5, 2016 07:21 — forked from carlosveucv/yaml_cmp.rb
Compare 2 yaml's in ruby (print matching keys)
require 'yaml'
def compare_yaml_hash(cf1, cf2, context = [])
cf1.each do |key, value|
if cf2.key?(key)
puts "Contains key : #{key} in path #{context.join(".")}"
end
value2 = cf2[key]
next unless value2

Subtree merging and you

If you’re using Git, you’re probably aware of submodules. They’re useful when you want to integrate and track another Git repository into your own. But there are two other options at your disposal.

The first one is to simply merge the other repository. This works fine as long as there are no conflicting files, but chances are there already are or will be in the future, which makes this option not too useful.

This is where the subtree merge strategy comes in. It allows you to merge another repository (let’s call it “Project B”) into your own, but into its own subdirectory. It takes a bit of effort to set everything up the first time, but after that a pull from the other repository is all that is needed to update.

Here’s how you set it up. First you need to add Project B as a remote: