Skip to content

Instantly share code, notes, and snippets.

@mbrezu
mbrezu / quasiquote.clj
Created November 5, 2009 06:58
quasiquote with unquote-splicing
(ns quasiquote
(:use clojure.test))
;; **************************************
;; Quasiquote from ClojureQL
;; http://gitorious.org/clojureql/clojureql/blobs/master/src/dk/bestinclass/clojureql/util.clj
;; modified to work with unquote-splicing
;; **************************************
@devongovett
devongovett / succ.js
Created July 13, 2011 20:39
An implementation of Ruby's string.succ method in JavaScript
/*
* An implementation of Ruby's string.succ method.
* By Devon Govett
*
* Returns the successor to str. The successor is calculated by incrementing characters starting
* from the rightmost alphanumeric (or the rightmost character if there are no alphanumerics) in the
* string. Incrementing a digit always results in another digit, and incrementing a letter results in
* another letter of the same case.
*
* If the increment generates a carry, the character to the left of it is incremented. This
@semperos
semperos / clojure-deftype-scaffolding.clj
Created October 4, 2012 18:16
Clojure Scaffolding for deftype (Christophe Grand) - Show which methods a class implements and for which interfaces
;; Big thanks to Christophe Grand - https://groups.google.com/d/msg/clojure/L1GiqSyQVVg/m-WJogaqU8sJ
(defn scaffold [iface]
(doseq [[iface methods] (->> iface .getMethods
(map #(vector (.getName (.getDeclaringClass %))
(symbol (.getName %))
(count (.getParameterTypes %))))
(group-by first))]
(println (str " " iface))
(doseq [[_ name argcount] methods]
(println
@darkf
darkf / ecs.py
Last active July 21, 2017 05:03
Hypothetical Entity-Component System in Python
# Let's define a hypothetical Entity-Component System for a one-dimensional text-based game.
# Copyright (c) 2013 darkf
# First authored 5/14/2013
# Licensed under the terms of the WTFPL
from magic import Game, Entity, Component, system, query
# Components are pure-data models
PositionC = Component(x=0)

The logical relations between Go scoring systems

What is the simplest Go scoring system? It's this:

  • Stone Scoring: just count the stones on the board

At the end of the game, both players will want to fill in as much of their own territory as they can, while allowing two eyes per group (so they aren't captured). Then the winner is just the player with more stones on the board. Note that prisoners are not counted.

But nobody wants to play all these extra stones at the end. So we can instead use:

@romainl
romainl / colorscheme-override.md
Last active July 14, 2024 01:08
The right way to override any highlighting if you don't want to edit the colorscheme file directly

The right way to override any highlighting if you don't want to edit the colorscheme file directly

Generalities first

Suppose you have weird taste and you absolutely want:

  • your visual selection to always have a green background and black foreground,
  • your active statusline to always have a white background and red foreground,
  • your very own deep blue background.
@bpatram
bpatram / publish-release.sh
Last active February 12, 2021 17:29
Release Notes Generator
#!/bin/bash
# ---------------------------
# Author: Brandon Patram
# Date: 2018-06-19
#
# Description: List out merge commits and one off commits between
# the last tagged release and the current state of master.
#
# Usage: publish-release.sh [-y] [-h] [-v] [-V]
# Examples:
(defonce ^Logger logger (doto (Logger/getLogger "clojure")
(.setUseParentHandlers false)
(.addHandler
(doto (ConsoleHandler.)
(.setLevel Level/ALL)
(.setFormatter
(proxy [SimpleFormatter] []
(format [^LogRecord record]
(let [sb (StringBuilder.)]
(.append sb "#:log{")
@gws
gws / cognitect_aws_api_web_identity.clj
Created December 31, 2020 18:33
Cognitect AWS API with web identity
;; Copyright 2020 Gordon Stratton
;;
;; Licensed under the Apache License, Version 2.0 (the "License");
;; you may not use this file except in compliance with the License.
;; You may obtain a copy of the License at
;;
;; http://www.apache.org/licenses/LICENSE-2.0
;;
;; Unless required by applicable law or agreed to in writing, software
;; distributed under the License is distributed on an "AS IS" BASIS,
thursday=> (info "foo")
#:log{:z "2021-03-02T19:12:51.470Z" :v :info :n thursday :l 1 :m "foo"}
nil
thursday=> (info "foo" {::a 1})
#:log{:z "2021-03-02T19:13:06.505Z" :v :info :n thursday :l 1 :m "foo" :thursday/a 1}
nil
thursday=> (info "foo" (Exception.))
#:log{:z "2021-03-02T19:15:19.396Z" :v :info :n thursday :l 1 :m "foo" :thrown
#error {
:cause nil