Skip to content

Instantly share code, notes, and snippets.

@fero23
fero23 / Benchmark.scala
Last active October 29, 2015 20:24
Gets and processes benchmark data from http://benchmarksgame.alioth.debian.org/u64q
object Benchmarks {
import io.Source
import util.{Try, Success}
case class Benchmark(name: String, lang: String, id: Int, n: Int, size: Int,
cpu: Double, mem: Int, status: Int, load: String, elapsed: Double)
object Benchmark { def fromSeq(s: Seq[String]) = Benchmark(s(0), s(1), s(2).toInt, s(3).toInt,
s(4).toInt, s(5).toDouble, s(6).toInt, s(7).toInt, s(8), s(9).toDouble) }
@fero23
fero23 / UnixDateTime.cs
Last active November 2, 2015 03:42
A simple Unix DateTime implementation
using System;
namespace fero23.DateTime
{
public class UnixDateTime
{
public enum WeekDays
{
Monday = 4,
Tuesday = 5,
@fero23
fero23 / htest.hs
Last active November 5, 2015 19:09
Haskell benchmark test
import System.CPUTime
wait :: a -> IO a
wait x = seq x (return x)
main :: IO ()
main = do
start <- getCPUTime
l <- wait . last $ map abs [1..1000000000]
end <- getCPUTime
{-# LANGUAGE OverloadedStrings #-}
module Formatter where
import Foreign.C.String
import Foreign.C.Types
import qualified Data.Text as T
foreign export ccall
format :: CString -> IO CString
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace HSTest
{
public partial class Form1 : Form
{
public Form1()
{
@fero23
fero23 / json.hs
Last active June 19, 2023 07:57
JSON Parser with Haskell's Parsec
import Text.ParserCombinators.Parsec
import Data.List
type Args = [String]
type Body = [String]
type Label = String
data JSONProp = JSONProp Label JSON deriving Show
data JSON = JSONObject [JSONProp]
| JSONNumber Double
@fero23
fero23 / decisionTree.hs
Last active December 5, 2015 17:11
A Haskell decision tree designer and solver (with some samples on spanish)
import Data.List (sortBy)
type Tag = String
type NodeData = (Tag, Double, Double, [Node])
data Node = DecisionNode NodeData | RandomNode Double NodeData deriving Show
data SortedNode = SortedNode {
tag::Tag,
isRandom::Bool,
isCase::Bool,
getValue::Double,
@fero23
fero23 / concurrency_test.rs
Created December 28, 2015 01:24
Rust concurrency test
use std::thread;
use std::sync::{Arc, Mutex};
fn main() {
const MAX_HAND: u32 = 5;
const PLAYERS: usize = 5;
let players: Arc<Mutex<Vec<u32>>> = Arc::new(Mutex::new(vec![0;PLAYERS]));
let dealer: Arc<Mutex<u32>> = Arc::new(Mutex::new(MAX_HAND));
@fero23
fero23 / novel_scrapper.js
Last active February 1, 2016 04:44
Random RSS blog feed compilator for my web novel needs
"use strict";
var cheerio = require("cheerio");
var request = require("request");
var _ = require("lodash");
var parseString = require('xml2js').parseString;
var ProgressWatcher = require("./progress_watcher");
let urls = {
drupal: [
@fero23
fero23 / state_monad_sample.hs
Created January 28, 2016 21:28
A small state monad example demonstrating the creation of a number stream collection accumulated in a string
type State = (String, Integer)
data ST x = S(State -> (x, State))
apply st (S f) = f st
instance Functor ST where
fmap f (S f') = S(\s -> let (x, s') = f' s in (f x, s'))
instance Applicative ST where
pure x = S(\s -> (x, s))