Skip to content

Instantly share code, notes, and snippets.

View gmichokostas's full-sized avatar

Yiorgos Michokostas gmichokostas

View GitHub Profile
@thegeez
thegeez / spec_parsing.clj
Last active December 30, 2023 18:17
Parsing with clojure.spec for the Advent of Code challenge
(ns net.thegeez.advent.spec-parsing
(:require [clojure.string :as str]
[clojure.spec :as s]
[clojure.spec.gen :as gen]
[clojure.test.check.generators :as tgen]))
;; Dependencies:
;; [org.clojure/clojure "1.9.0-alpha14"]
;; [org.clojure/test.check "0.9.0"]
;; Advent of Code is a series of code challenges in the form of an advent
@reborg
reborg / rich-already-answered-that.md
Last active January 23, 2025 22:49
A curated collection of answers that Rich gave throughout the history of Clojure

Rich Already Answered That!

A list of commonly asked questions, design decisions, reasons why Clojure is the way it is as they were answered directly by Rich (even when from many years ago, those answers are pretty much valid today!). Feel free to point friends and colleagues here next time they ask (again). Answers are pasted verbatim (I've made small adjustments for readibility, but never changed a sentence) from mailing lists, articles, chats.

How to use:

  • The link in the table of content jumps at the copy of the answer on this page.
  • The link on the answer itself points back at the original post.

Table of Content

@noteflakes
noteflakes / pgstore.rb
Last active July 6, 2023 18:36
A lightweight PostgreSQL ORM using JSONB. Provides an API for retreiving documents by arbitrary key, and performing queries on arbitrary keys and sub-keys.
require 'pg'
PGDB = PG.connect(host: '/tmp', dbname: 'mydb')
PGDB.type_map_for_results = PG::BasicTypeMapForResults.new(PGDB)
class Hash
def symbolize_keys
inject({}) { |m, kv| v = kv[1];
m[kv[0].to_sym] = v.is_a?(Hash) ? v.symbolize_keys : v; m }
end
end
@ericnormand
ericnormand / 00_script.clj
Last active February 22, 2025 10:41
Boilerplate for running Clojure as a shebang script
#!/bin/sh
#_(
#_DEPS is same format as deps.edn. Multiline is okay.
DEPS='
{:deps {clj-time {:mvn/version "0.14.2"}}}
'
#_You can put other options here
OPTS='
@jhawthorn
jhawthorn / benchmark_first_request.rb
Last active September 10, 2019 17:55
Script to benchmark the initial request after a fork. Records stats and makes a flamegraph
REQUEST_URI = ARGV[0] || "http://0.0.0.0/"
REQUEST_OPTS = {
'REMOTE_ADDR' => "127.0.0.1",
'HTTP_HOST' => '0.0.0.0'
}
ARGV.clear
require "actionview_precompiler"
require "flamegraph"
require "./config/environment"
@finalfantasia
finalfantasia / shadow_cljs_and_fireplace_vim_integration.md
Last active September 25, 2024 20:29
Shadow-CLJS and Fireplace.vim Integration
  1. Create an app following the official Shadow-CLJS Quick Start instructions.
  2. Modify shadow-cljs.edn
;; shadow-cljs configuration
{:source-paths
 ["src/dev"
  "src/main"
  "src/test"]

 ;; ADD - CIDER middleware for nREPL (required by fireplace.vim)
@JoshCheek
JoshCheek / json_parse.rb
Created April 22, 2020 20:43
Not sure why, but I suddenly felt compelled to make a JSON parser 🤷‍♂️
def json_parse(json)
success, index, _ws = json_parse_optional_whitespace(0, json)
success, index, value = json_parse_value(index, json)
raise "Could not parse" unless success
value
end
def json_parse_value(index, json)
%I[
json_parse_null
@mikeananev
mikeananev / jvm.clj
Last active March 29, 2023 12:42
Create JVM Heap Dump and Thread Dump using Clojure
;; Copyright (c) Mikhail Ananev, 2020.
;; Red Stars Systems (https://rssys.org).
;;
;; Licensed to the Apache Software Foundation (ASF) under one
;; or more contributor license agreements. See the NOTICE file
;; distributed with this work for additional information
;; regarding copyright ownership. The ASF licenses this file
;; to you 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
@tenderlove
tenderlove / ngpng.rb
Last active December 12, 2020 14:09
Simple PNG generation example that only depends on zlib in Ruby
# Not Great PNG class. This is a very simple example of writing a PNG. It
# only supports colors from the color palette stored in `@palette`. This is
# meant to be example code, but I am using it in a program for visualizing
# heap dumps from Ruby.
#
# This is free and unencumbered software released into the public domain.
#
# Anyone is free to copy, modify, publish, use, compile, sell, or
# distribute this software, either in source code form or as a compiled
# binary, for any purpose, commercial or non-commercial, and by any