Skip to content

Instantly share code, notes, and snippets.

View Medeah's full-sized avatar

Frederik Andersen Medeah

  • The Restaurant at the End of the Universe
  • 19:58 (UTC +01:00)
View GitHub Profile
@Medeah
Medeah / gist:5127545
Created March 10, 2013 07:50
A Tour of Go 23: Exercise: Loops and Functions
package main
import (
"fmt"
"math"
)
// square root function using Newton's method
func Sqrt(x float64) float64 {
z := 1.0
@Medeah
Medeah / gist:5127581
Created March 10, 2013 08:07
A Tour of Go 35: Exercise: Slices
package main
import "code.google.com/p/go-tour/pic"
func Pic(dx, dy int) [][]uint8 {
slicePic := make([][]uint8, dy)
for y := range slicePic {
slicePic[y] = make([]uint8, dx)
for x := range slicePic[y] {
slicePic[y][x] = uint8(x ^ y)
@Medeah
Medeah / gist:5127618
Created March 10, 2013 08:22
A Tour of Go 40: Exercise: Maps
package main
import (
"code.google.com/p/go-tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
wordCount := make(map[string]int)
for _, word := range strings.Fields(s) {
@Medeah
Medeah / gist:5127681
Created March 10, 2013 08:48
A Tour of Go 43: Exercise: Fibonacci closure
package main
import "fmt"
// fibonacci is a function that returns
// a function that returns an int.
func fibonacci() func() int {
// we use seed values of F_−2 and F_−1
// that way the first fibonacci number returned will be F_0
a, b := -1, 1
@Medeah
Medeah / gist:5128961
Created March 10, 2013 15:16
A Tour of Go 47: Advanced Exercise: Complex cube roots
package main
import (
"fmt"
"math/cmplx"
)
func Cbrt(x complex128) complex128 {
z := complex(1.0, 0)
for cmplx.Abs(z*z*z-x) > 1e-9 {
var fs = require('fs')
fs.readFile('words-da', function(err, data) {
if(err) throw err
var array = data.toString().split("\n")
var avl = {}
for(i in array) {
avl[array[i]] = 1
@Medeah
Medeah / gist:2bc6e92b86ae7e8abc14
Last active December 15, 2016 22:21
Pending tests in clojure.test
;; This is free and unencumbered software released into the public domain.
;; Assume nothing works, and you may be pleasantly surprised; and when it breaks, you get to keep both pieces.
;; A Simple macro that enables you to change your testing groups to pending
(defmacro pending [name & body]
(let [message (str "\n" name " is pending !!")]
`(testing ~name (println ~message))))
@Medeah
Medeah / Main.java
Created March 28, 2015 09:29
Accenture challenge using algorithm implementation from here: http://algs4.cs.princeton.edu/code/
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
public class Main {
private static int getNode(int i, int j) {
return i * 1000 + j;
}
@Medeah
Medeah / updatehosts.sh
Last active September 21, 2015 18:04
Simple script to get the newest hostfile from http://someonewhocares.org/hosts/
# This is free and unencumbered software released into the public domain.
# Assume nothing works, and you may be pleasantly surprised; and when it breaks, you get to keep both pieces.
wget http://someonewhocares.org/hosts/zero/hosts && \
echo "127.0.0.1 $(cat /etc/hostname)" >> hosts && \
sudo cp /etc/hosts /etc/hosts.bak && \
sudo mv hosts /etc/hosts && \
grep --color=auto "Last updated" /etc/hosts
@Medeah
Medeah / index.html
Created September 15, 2015 15:28
Recover private key from vertpunk wallet
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<!--This is free and unencumbered software released into the public domain.-->
<title>Recover private key</title>
<script src="https://cdn.rawgit.com/bitwiseshiftleft/sjcl/1.0.3/sjcl.js"></script>
<script>
function submit() {
var id = document.getElementsByTagName('input')[0].value;