Skip to content

Instantly share code, notes, and snippets.

View heftig's full-sized avatar
🦄
Horsing around

Jan Alexander Steffens heftig

🦄
Horsing around
View GitHub Profile
def replace_line_in_file(old,new,file)
File.open(file) do |f|
File.open(file + ".new", "w") do |f2|
f.each_line do |line|
f2.puts line.gsub(old, new)
end
end
end
File.rename(file + ".new", file)
end
class Hash
def map_value
each_pair.with_object({}) { |(key, value), result| result[key] = yield value }
end
def map_key
each_pair.with_object({}) { |(key, value), result| result[yield key] = value }
end
def map_pair(&blk)
@heftig
heftig / code.rb
Last active August 29, 2015 14:14
def evaluate(expression)
stack = []
expression.split.each do |word|
case word
when "+"
stack << (stack.pop + stack.pop)
when "-"
arg1 = stack.pop
arg2 = stack.pop
@heftig
heftig / test.c
Last active August 29, 2015 14:28 — forked from Gikoskos/test.c
memory problem in C
#include <unistd.h>
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
char *foo2 ()
{
return "FOO";
}

I have an example YAML file:

---
- foo:
    - 1
    - 2
    - 3

- bar: test123
- lol: test456