Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:

Javier Neira jneira

:octocat:
View GitHub Profile
@jneira
jneira / PureIO.cs
Created Sep 7, 2017 — forked from tonymorris/PureIO.cs
A demonstration of pure-functional I/O using the free monad in C#
View PureIO.cs
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 Aug 25, 2017 — forked from davinkevin/MultipartFileSender
Implementing HTTP byte-range requests in Spring 4 and other framework...
View MultipartFileSender.java
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;
View RandomWalk.hs
{-# 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)
View prior.clj
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,
View multimethods.clj
;; 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))
View simple_floyd.hs
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
View Warshall.hs
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 Dec 11, 2015 — forked from anonymous/PrincipalSpec.class
Trying to compose spock specs with mixins
View PrincipalSpec.class
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 Sep 7, 2012 — forked from michiakig/ants.clj
Clojure ant sim from Rich Hickey
View ants.clj
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 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
View rand_tree.clj
(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?)