Skip to content

Instantly share code, notes, and snippets.

View callerobertsson's full-sized avatar
Converting coffee to code

Calle Robertsson callerobertsson

Converting coffee to code
View GitHub Profile
@callerobertsson
callerobertsson / main.go
Last active January 31, 2022 11:53
Golang: Stable sort on priority and order
package main
import (
"fmt"
"sort"
)
// Item has a priority and an order
type Item struct {
Prio int
@callerobertsson
callerobertsson / fibonacci.go
Last active January 14, 2022 15:49
Golang: Fibonacci Big Number
package main
import (
"fmt"
"math/big"
)
func main() {
for i := 1; i <= 10; i++ {
@callerobertsson
callerobertsson / fibonacci.hs
Last active November 22, 2017 17:00
Haskell: Fibonacci Big Number
module Main where
main = do
print $ map fibN' [1..10]
print $ fibN' 1001
print $ length $ show $ fibN' 500000
fibN' 1 = 0
fibN' 2 = 1
fibN' n = iter 0 1 n where
@callerobertsson
callerobertsson / wc.hs
Last active February 16, 2017 08:31
Haskell: Simple wc command (no options)
module Main where
import Text.Printf
main = do
input <- getContents
printf "%8d%8d%8d\n"
(length (lines input))
(length (words input))
(length input)
@callerobertsson
callerobertsson / downcast.cs
Last active August 19, 2016 08:48
C#: True down cast from child to parent using JSON
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
namespace DownCaster
{
static class Program
{
static void Main()
@callerobertsson
callerobertsson / kanal.go
Created June 20, 2015 09:51
Golang: Playing with a queue channel
package main
import (
"bufio"
"fmt"
"math/rand"
"os"
"strconv"
"time"
)
@callerobertsson
callerobertsson / page-template.html
Created May 14, 2013 06:51
HTML: Page template #snippet
<!DOCTYPE html>
<!-- by calle@stenhall.com -->
<html>
<head>
<title>TITLE</title>
<style>
@import url("reset.css");
@import url("style.css");
</style>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
@callerobertsson
callerobertsson / filterFile.js
Created May 13, 2013 15:53
Javascript (NodeJS): A simple script for extracting parts in a textfile between two regex matching lines. #snippet
// Filter File
// a simple script for extracting parts in a textfile between two lines.
// by Calle Robertsson, calle@upset.se, 2013.
var fs = require('fs');
var filename = process.argv[2];
if (!filename) {
throw new Error('Missing command line argument for file name.');
@callerobertsson
callerobertsson / compareObjects.js
Created April 28, 2013 22:18
Javascript: Object comparision with ignored fields. Original source can be found at http://www.sencha.com/forum/showthread.php?59240-Compare-javascript-objects but without ignored fields. #snippet
// The javascript compare objects function
function compareObjects(o1, o2, ignoreFields){
ignoreFields = ignoreFields || [];
//console.log('Ignore: ' + JSON.stringify(ignoreFields));
for(var p in o1) {
if (ignoreFields.indexOf(p) < 0) {
if(o1[p] !== o2[p]){
return false;
}
}
@callerobertsson
callerobertsson / gopastebin.go
Last active August 29, 2015 14:27
Golang: Command line wrapper for posting to pastebin.com
package main
import (
"flag"
"fmt"
"io/ioutil"
"net/http"
"net/url"
"os"
"strconv"