Skip to content

Instantly share code, notes, and snippets.

View jneira's full-sized avatar
:octocat:

Javier Neira jneira

:octocat:
View GitHub Profile
@jneira
jneira / PureIO.cs
Created September 7, 2017 21:40 — forked from tonymorris/PureIO.cs
A demonstration of pure-functional I/O using the free monad in C#
using System;
namespace PureIO {
/*
C# does not have proper sum types. They must be emulated.
This data type is one of 4 possible values:
- WriteOut, being a pair of a string and A
- WriteErr, being a pair of a string and A
- readLine, being a function from string to A
@jneira
jneira / MultipartFileSender.java
Last active March 10, 2023 17:49 — forked from davinkevin/MultipartFileSender
Implementing HTTP byte-range requests in Spring 4 and other framework...
package lan.dk.podcastserver.utils.multipart;
import lan.dk.podcastserver.utils.MimeTypeUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Control.Monad.Trans (lift)
import Control.Parallel (par, pseq)
import Data.Text.Lazy (pack)
import System.Random (StdGen, newStdGen, random)
import Web.Scotty (get, scotty, text)
@jneira
jneira / prior.clj
Last active December 18, 2015 07:18
tenemos una lista ordenada (por :priority) de objetos. debe poder accederse por índice (lo que al menos en clj, descarta la posibilidad de usar un set).
puede haber múltiples objetos con el mismo valor :priority.
[{:priority 1} {:priority 1} {:priority 3} {:priority 3} {:priority 3} {:priority 5} {:priority 5} {:priority 8} {:priority 8} {:priority 8}]
en mi dominio, cada objeto tiene más claves aparte de :priority, pero son irrelevantes en este problema.
lo que deseamos es un método que nos dé el índice de acceso de un elemento al azar, un azar influido por las prioridades.
digamos que dos objetos con la misma :priority tienen elegibilidad equiprobable,
;; Se define en un modulo una funcion polimorfica en funcion del tipo
;; de los *dos argumentos*
(ns modulo1)
(defmulti write (fn [writer data] [(type writer) (:type data)])
;; En otro modulo que importa la definicion anterior generica de write
(ns modulo2 (require modulo1))
(defmethod modulo1/write [java.io.FileWriter :user] [writer user]
(comment codigo especifico usando el FileWriter y teniendo en cuenta
que los datos son del tipo :usuario))
module JJFW where
import Data.Map hiding (map)
import Data.Array.IO
import Control.Monad (forM_)
import System.Time
import System.IO
type Edge = (Int,Int)
type EdgeCost = (Edge,Int)
type IOAcc = IOUArray (Int,Int) Int
module Warshall where
import Data.Char ( isAlpha )
import Data.List ( nub, sort )
import System.Environment ( getArgs )
import Text.Parsec
import Text.Parsec.String
import Text.Printf ( printf )
type Vertex a = a
@jneira
jneira / PrincipalSpec.class
Last active December 11, 2015 06:59 — forked from anonymous/PrincipalSpec.class
Trying to compose spock specs with mixins
import grails.plugin.spock.UnitSpec;
import org.codehaus.groovy.runtime.ArrayUtil;
import org.codehaus.groovy.runtime.callsite.CallSite;
import org.spockframework.runtime.model.FeatureMetadata;
import org.spockframework.runtime.model.FieldMetadata;
import org.spockframework.runtime.model.SpecMetadata;
@SpecMetadata(filename="PrincipalSpec.groovy")
public class PrincipalSpec extends UnitSpec
{
@jneira
jneira / ants.clj
Created September 7, 2012 15:26 — forked from michiakig/ants.clj
Clojure ant sim from Rich Hickey
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Ant sim ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Copyright (c) Rich Hickey. All rights reserved.
; The use and distribution terms for this software are covered by the
; Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
; which can be found in the file CPL.TXT at the root of this distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.
;dimensions of square world
(ns rand-tree)
(defn seed []
(let [r #(when (zero? (rand-int 2)) seed)]
{:left (r)
:right (r)}))
(def seed? fn?)
(def leaf? nil?)
(def branch? map?)