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.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 / 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 / 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"
@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 / jsonformat.js
Created May 26, 2015 06:56
Javascript: JSON Formatter
// jsonformat.js
// a simple script that format JSON data in a more readable way.
// by Calle Robertsson, [email protected], 2015.
var fs = require('fs');
var filename = process.argv[2];
if (!filename) {
throw new Error('Missing command line argument for file name.');
}
@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 / pad.js
Created March 13, 2015 13:03
Javascript: Pad string but don't truncate if too long
// Javascript Pad String
// Inspired by http://dev.enekoalonso.com/2010/07/20/little-tricks-string-padding-in-javascript/
function pad(filling, value) {
if (('' + value).length > filling.length) {
return value;
}
return (filling + value).slice(-1 * filling.length);
}
@callerobertsson
callerobertsson / empty-string-is-a-number.js
Last active August 29, 2015 14:16
Javascript: Empty string is a number
if (isNaN("")) {
console.log('Empty string is not a number');
}
else {
console.log('Empty string IS a number!!!');
}
// => Empty string IS a number!!!