Skip to content

Instantly share code, notes, and snippets.

Avatar

Mikael Henriksson mhenrixon

View GitHub Profile
@mhenrixon
mhenrixon / dotify_spec.rb
Last active Aug 29, 2015
How to dotify a ruby hash (to be able to more easily convert it to a java like dot notated config file)
View dotify_spec.rb
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 / add_missing_newline.sh
Created Apr 22, 2014
Recursively adds newline to the end of every file with the .rb extension
View add_missing_newline.sh
for file in **/*.rb; do
[ -e "$file" ] || continue
if [[ -n "$(tail -c 1 <"$file")" ]]; then
echo >> "$file"
fi;
done
@mhenrixon
mhenrixon / 0_reuse_code.js
Last active Aug 29, 2015
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
View stub_partial_search.rb
# Public: Stubs partial search
# Examples =>
# stub_partial_search(:node, 'name:web*').and_return([{ 'fqdn' => 'web01.example.com' }])
#
def stub_partial_search(type, query)
allow(Chef).to receive(:partial_search).and_call_original
expect(Chef).to receive(:partial_search).with(type, query, any_args)
end
View tmux-cheatsheet.markdown

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
View circle.yml
machine:
services:
- 'postgresql'
- 'redis'
environment:
REDIS_URL: 'redis://localhost:6379/0'
dependencies:
pre:
- 'git config user.email deploy+$CIRCLE_USERNAME@brandfolder.com'
- 'git config user.name $CIRCLE_USERNAME'
@mhenrixon
mhenrixon / DiagnostigsReport.log
Last active Aug 29, 2015
let_it_go crash reports
View DiagnostigsReport.log
Process: ruby [19993]
Path: /Users/USER/*/ruby
Identifier: ruby
Version: 0
Code Type: X86-64 (Native)
Parent Process: zsh [14987]
Responsible: iTerm2 [11084]
User ID: 501
Date/Time: 2015-08-18 13:55:44.681 +0200
@mhenrixon
mhenrixon / after.txt
Created Aug 20, 2015
A comparison of before and after optimizing for memory usage and performance.
View after.txt
Total allocated: 526174 bytes (9496 objects)
Total retained: 680 bytes (17 objects)
allocated memory by gem
-----------------------------------
526174 wodconnect/app
allocated memory by file
-----------------------------------
152252 /Users/mhenrixon/code/kiskolabs/wodconnect/app/models/bill.rb
View Chilkat verify - Fail
public static string OpenSslVerify(string publicKeyFile, string signedContent)
{
var pkey = new PublicKey();
pkey.LoadOpenSslPemFile(publicKeyFile);
string pkeyXml = pkey.GetXml();
var rsa = new Rsa();
bool success = rsa.UnlockComponent("30-day trial");
if (success != true)
{
View IHideObjectMembers
using System;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
namespace Moq
{
[EditorBrowsable(EditorBrowsableState.Never)]
public interface IHideObjectMembers
{
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate",