Skip to content

Instantly share code, notes, and snippets.

View cyppan's full-sized avatar

Cyprien Pannier cyppan

View GitHub Profile
⍝ DAY 1
in←⊃⎕nget'01.txt'1
digitsStr←'one' 'two' 'three' 'four' 'five' 'six' 'seven' 'eight' 'nine'
mask←{(⍳9)+.×↑(⍷∘⍺)¨⍵}
part1←+/{10⊥(⊃,¯1∘↑)(⍵ mask '123456789')~0}¨in
part2←+/{10⊥(⊃,¯1∘↑)((⍵ mask '123456789')∨⍵ mask digitsStr)~0}¨in
⍝ DAY 2
@cyppan
cyppan / configBuilder.ts
Last active July 4, 2022 15:50
Typescript Config Builder
interface SsmParameter {
ssmName: string;
ssmType: "String" | "SecureString";
configType?: "string" | "number" | "boolean";
}
class SsmConfig<Config, C extends Record<string, SsmParameter> = {}> {
constructor(private config: C) {}
static builder<Config>(): SsmConfig<Config, {}> {
return new SsmConfig<Config, {}>({});
@cyppan
cyppan / day12.clj
Created December 12, 2021 21:29
Advent of Code 2021 - day 12: Passage Pathing
(ns aoc.day12
(:require [clojure.java.io :as io]
[clojure.string :as str]))
(defn parse-input [file-name]
(reduce (fn [graph [a b]]
(-> graph
(update a conj b)
(update b conj a)))
{}
(ns dev.pathom-playground
(:require [com.wsscode.pathom3.connect.indexes :as pci]
[com.wsscode.pathom3.connect.operation :as pco]
[com.wsscode.pathom3.interface.eql :as p.eql]))
;; that one works fine
(pco/defresolver timezone-resolver [item]
{::pco/input [:timezone/id]
::pco/output [:timezone/label]}
{:timezone/label (str "label for id " (:timezone/id item))})
@cyppan
cyppan / unserializePhp.js
Last active November 19, 2020 12:39
Javascript (very incomplete) port of the "unserialize" PHP function
function unserialize(serialized) {
serialized = serialized.split("")
const res = []
const parseNumber = () => {
next = serialized.shift()
let digits = ""
while (!isNaN(parseInt(next))) {
digits += next
next = serialized.shift()
@cyppan
cyppan / playground.clj
Created May 3, 2020 18:59
core.logic crops planification POC
(ns playground
(:refer-clojure :exclude [==])
(:use clojure.core.logic)
(:require [java-time :as jt]
[clojure.core.logic.fd :as fd]))
;; INITIAL DATA
(def nb-parcells 4)
(def days-to-plan 10)
(def crop-growth-days 3)
@cyppan
cyppan / index.js
Created December 7, 2018 14:19
serve-sequelize
const express = require('express');
const cors = require('cors');
const bodyParser = require('body-parser');
const {
connect, syncDb, buildAndRegisterModel, setupAssociations, mapException, mapQueryParams
} = require('serve-sequelize');
const app = express();
const sequelize = connect({
@cyppan
cyppan / cookie.clj
Created August 14, 2015 08:25
Clojure parse cookie string
@cyppan
cyppan / iab.clj
Created August 4, 2015 06:16
If you use AlchemyAPI and want to map its categories to IAB ones you may find this get-iabs function useful
(ns alchemyapi.iab)
(def iab-categories
{"IAB1" "Arts_Entertainment"
"IAB1-1" "Arts_Entertainment/Books & Literature"
"IAB1-2" "Arts_Entertainment/Celebrity Fan/Gossip"
"IAB1-3" "Arts_Entertainment/Fine Art"
"IAB1-4" "Arts_Entertainment/Humor"
"IAB1-5" "Arts_Entertainment/Movies"
"IAB1-6" "Arts_Entertainment/Music"
@cyppan
cyppan / logger.py
Created May 27, 2015 17:38
python logging
import logging
import sys
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler(sys.stdout)
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)