Skip to content

Instantly share code, notes, and snippets.

Avatar

Juan María Hernández jmhdez

View GitHub Profile
View core.clj
(ns rpg-kata-clj.core
(:require [clojure.set :refer [intersection]]))
(defrecord Entity [health level attack factions type])
(defn new-character []
(->Entity 1000 1 :melee #{} :character))
(defn new-prop [health]
(->Entity health 1 :melee #{} :property))
@jmhdez
jmhdez / zebra-puzzle-loco.clj
Last active May 23, 2016
Solving the zebra puzzle with loco
View zebra-puzzle-loco.clj
(ns loco-playground.core
(:require [loco.core :refer :all]
[clojure.pprint :refer :all]
[loco.constraints :refer :all]))
;; http://bypacoman.blogspot.com.es/2013/08/desestructurando-el-puzzle-de-einstein.html
;; ---- Datos de referencia
(def domain
View 8queens-loco.clj
;; depends on [loco "0.3.1"]
(ns loco-playground.core
(:require [loco.core :refer :all]
[loco.constraints :refer :all]))
(def queens-model
(conj
;; Variables [:x i] [:y i] para la posición de la reina i-ésima
(mapcat #(vector ($in [:x %] 0 7) ($in [:y %] 0 7)) (range 8))
;; Todas las filas deben ser distintas
View gist:ffe758a6c38554daf2a4
"scripts": {
"browserify": "browserify lib/index.js -o dist/app.js -t [babelify --presets [es2015 react]]",
"dev": "nodemon --watch lib --exec npm run browserify"
},
@jmhdez
jmhdez / MachineLearning.cs
Last active Aug 29, 2015
Ejemplo de uso de numl para generar árboles de decisión mediante aprendizaje automático sobre un corpus de Princesas Disney
View MachineLearning.cs
// Require instalar el paquete numl desde NuGet
using System;
using numl;
using numl.Model;
using numl.Supervised.DecisionTree;
namespace MachineLearning
{
public enum HairColor
View gist:46de62a0520bd0c8081b
(def double-partial (partial * 2))
(defn double-fn [x] (* 2 x))
(time
(dotimes [n 10000000]
(double-partial 5)))
;; => "Elapsed time: 3139.323652 msecs"
(time
@jmhdez
jmhdez / sample.cs
Created Sep 16, 2014
Maybe<T> Sample
View sample.cs
public IEnumerable<ProductSalesEntry> GetProductSales(Maybe<User> user, DateTime fromDate, DateTime toDate)
{
// El método puede recibir o no un usuario o un Maybe<User>.Empty.
// Si recibe un usuario, se pasa su Id a la consulta SQl, si no,
// se pasa 0 y la consulta SQL no filtrará por usuario;
// vamos, el típico where (user.Id = @userId or @userId = 0)
// Para hacer explícito que el usuario es un parámetro opcional del método, se
// define como un Maybe<User>. Se converte en un Maybe<int> para obtener el Id
// usando "select" (el bind de cualquier mónada, pero más C# friendly) y finalmente
@jmhdez
jmhdez / ko-chart.js
Last active Feb 11, 2019
Custom bindings to use Chart.js with Knockout.js
View ko-chart.js
/*global ko, Chart */
(function(ko, Chart) {
ko.bindingHandlers.chartType = {
init: function(element, valueAccessor, allBindings, viewModel, bindingContext) {
if (!allBindings.has('chartData')) {
throw Error('chartType must be used in conjunction with chartData and (optionally) chartOptions');
}
},
@jmhdez
jmhdez / marvel-api.clj
Last active Feb 23, 2018
Using the Marvel API from clojure
View marvel-api.clj
;; required deps [clj-http "0.9.2"]
(ns marvel-clj.core
(:require [clj-http.client :as http]
[clj-http.util :as util]
[clojure.string :as str])
(:gen-class))
(def public-key "YOUR_PUBLIC_KEY_HERE")
(def private-key "YOUR_PRIVATE_KEY_HERE")
@jmhdez
jmhdez / PlayerFactory.cs
Created May 7, 2014
Refactoring switch to Dictionary
View PlayerFactory.cs
using System;
using System.Collections.Generic;
using Model.Strategies;
using Model.Strategies.Minimax;
namespace Model
{
public class PlayerFactory
{
private ITwoPlayersGame TwoPlayersGame { get; set; }
You can’t perform that action at this time.