Skip to content

Instantly share code, notes, and snippets.

Calle Robertsson callerobertsson

Block or report user

Report or block callerobertsson

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@callerobertsson
callerobertsson / main.go
Last active Jun 20, 2017
Golang: Stable sort on priority and order
View main.go
package main
import (
"fmt"
"sort"
)
// Item has a priority and an order
type Item struct {
Prio int
@callerobertsson
callerobertsson / fibonacci.hs
Last active Nov 22, 2017
Haskell: Fibonacci Big Number
View fibonacci.hs
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 Dec 2, 2017
Golang: Fibonacci Big Number
View fibonacci.go
package main
import (
"fmt"
"math/big"
)
func main() {
for i := 1; i <= 10; i++ {
@callerobertsson
callerobertsson / gopastebin.go
Last active Aug 29, 2015
Golang: Command line wrapper for posting to pastebin.com
View gopastebin.go
package main
import (
"flag"
"fmt"
"io/ioutil"
"net/http"
"net/url"
"os"
"strconv"
@callerobertsson
callerobertsson / kanal.go
Created Jun 20, 2015
Golang: Playing with a queue channel
View kanal.go
package main
import (
"bufio"
"fmt"
"math/rand"
"os"
"strconv"
"time"
)
@callerobertsson
callerobertsson / jsonformat.js
Created May 26, 2015
Javascript: JSON Formatter
View jsonformat.js
// jsonformat.js
// a simple script that format JSON data in a more readable way.
// by Calle Robertsson, calle@upset.se, 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 Feb 16, 2017
Haskell: Simple wc command (no options)
View wc.hs
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 Aug 19, 2016
C#: True down cast from child to parent using JSON
View downcast.cs
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 Mar 13, 2015
Javascript: Pad string but don't truncate if too long
View pad.js
// 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 Aug 29, 2015
Javascript: Empty string is a number
View empty-string-is-a-number.js
if (isNaN("")) {
console.log('Empty string is not a number');
}
else {
console.log('Empty string IS a number!!!');
}
// => Empty string IS a number!!!
You can’t perform that action at this time.