Skip to content

Instantly share code, notes, and snippets.

View mhenrixon's full-sized avatar
🐢
I may be slow to respond.

Mikael Henriksson mhenrixon

🐢
I may be slow to respond.
View GitHub Profile
@mhenrixon
mhenrixon / cs_merge
Last active February 1, 2020 03:43
How we merged multiple github repos into a monolithic project repo
#!/bin/bash
#
# This script merges all the repos we have into subfolders in a new repo
#
# Clones or copies a repository from either disc or remote repository.
cloppy() {
local dir=$1
if [[ -z $2 ]]; then
local repo=$dir
@mhenrixon
mhenrixon / dotify_spec.rb
Last active August 29, 2015 13:57
How to dotify a ruby hash (to be able to more easily convert it to a java like dot notated config file)
def dotify(hash, k = [])
return {k.join('.') => hash} unless hash.is_a?(Hash)
hash.inject({}){ |h, v| h.merge! dotify(v[-1], k + [v[0]]) }
end
describe "dotify" do
let(:hash) { { foo: { bar: { baz: true } } } }
it "converts hash to dot notated keys" do
expect(dotify(hash)).to eq("foo.bar.baz" => true)
@mhenrixon
mhenrixon / call_for_receive_message_chain.rb
Last active December 27, 2015 22:29
This is my case for why I want to stub a chain of messages. Even if you take a look at the refactored version that test could still contain a bug. What I want to test is that some external object. In the last alternative not only does the test code become ugly but the implementation does too. I only use this for rails associations to keep stuff …
# I usually end up with something like below in my code
def fetch_something
current_something.coll_association.find_by some: 123, other: 'sasd'
end
# I want to test that the finder gets called with the right arguments
it "finds cool_association using the right arguments" do
expect(current_something).to receive_message_chain('cool_association.find_by').
with(some: 123, other: 'sasd') { cool_association }
end
Update server
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
sudo reboot
Enable Swedish locale and utf-8
sudo locale-gen sv_SE.UTF-8
sudo dpkg-reconfigure locales
Open sudo vim /etc/environment and add the folowing lines
@mhenrixon
mhenrixon / dns_cache.sh
Created April 17, 2013 11:48
How to flush dns cache on Mac OS X
dscacheutil -flushcache
@mhenrixon
mhenrixon / getJSON.js
Created March 15, 2013 10:23
fetching widgets
$.getJSON("/admin/widgets", function(data) {
$.each(data, function(index, object) {
var widget = object.table;
console.log('widget id:' + widget.id, + ', name' + widget.name);
});
});
@mhenrixon
mhenrixon / pkill.sh
Created March 10, 2013 13:32
How to kill all processes with a specific name (no questions asked)
#!/bin/sh
for X in `ps acx | grep -i $1 | awk {'print $1'}`; do
kill $X;
done
@mhenrixon
mhenrixon / uninstall_gems.sh
Created March 8, 2013 09:11
Uninstalls all gems under ruby 2.0. This way the system gems won't halt the uninstallation process upon throwing exceptions
for gem in `gem list --no-version`; do
gem uninstall -aIx $gem
done
# Example usage:
require 'active_record/nonpersisted_attribute_methods'
class Node < ActiveRecord::Base
include ActiveRecord::NonPersistedAttributeMethods
define_nonpersisted_attribute_methods [:bar]
# Example of using with ancestry and getting :parent to show up in changes hash.
has_ancestry
define_nonpersisted_attribute_methods [:parent]
common: &default_settings
adapter: mysql2
host: localhost
username: root
encoding: utf8
reconnect: false
pool: 5
development:
<<: *default_settings