Skip to content

Instantly share code, notes, and snippets.

@michiakig
michiakig / ants.clj
Created July 19, 2011 22:37
Clojure ant sim from Rich Hickey
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 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
@carolineschnapp
carolineschnapp / gist:5397337
Last active January 20, 2023 10:11
Sample JavaScript file added with ScriptTag resource. This sample file is meant to teach best practices. Your app will load jQuery if it's not defined. Your app will load jQuery if jQuery is defined but is too old, e.g. < 1.7.
/* Sample JavaScript file added with ScriptTag resource.
This sample file is meant to teach best practices.
Your app will load jQuery if it's not defined.
Your app will load jQuery if jQuery is defined but is too old, e.g. < 1.7.
Your app does not change the definition of $ or jQuery outside the app.
Example: if a Shopify theme uses jQuery 1.4.2, both of these statements run in the console will still return '1.4.2'
once the app is installed, even if the app uses jQuery 1.9.1:
jQuery.fn.jquery => "1.4.2"
$.fn.jquery -> "1.4.2"
*/
@msgodf
msgodf / core_async_merge_behaviour.clj
Created March 5, 2014 17:07
Some code to test the behaviour of Clojure core.async's merge function. Given two channels that produce values at a given intervals, merge them and see whether the two sequences are interleaved or concatenated.
(require '[clojure.core.async :as async refer [<! go timeout])
(defn sleepy-val
[v t]
(go (<! (timeout t)) v))
;; Will this produce [1 2 3 1.5 2.5 3.5] or [1 1.5 2 2.5 3 3.5]?
(go
(prn (<! (async/into []
(async/merge [(.async/merge [(sleepy-val 1 1000)
@john2x
john2x / 00_destructuring.md
Last active May 5, 2025 14:54
Clojure Destructuring Tutorial and Cheat Sheet

Clojure Destructuring Tutorial and Cheat Sheet

(Related blog post)

Simply put, destructuring in Clojure is a way extract values from a datastructure and bind them to symbols, without having to explicitly traverse the datstructure. It allows for elegant and concise Clojure code.

Vectors and Sequences

@zhy0
zhy0 / ubuntu-cli-install-android-sdk.sh
Last active April 3, 2025 18:18
Install Android SDK on headless Ubuntu linux machine via command line, so that you can compile open source Android apps.
#!/bin/bash
# Thanks to https://gist.github.com/wenzhixin/43cf3ce909c24948c6e7
# Execute this script in your home directory. Lines 17 and 21 will prompt you for a y/n
# Install Oracle JDK 8
add-apt-repository ppa:webupd8team/java
apt-get update
apt-get install -y oracle-java8-installer
apt-get install -y unzip make # NDK stuff
@outofcoffee
outofcoffee / find-ecr-image.sh
Last active March 1, 2024 13:35
Check if Docker image exists with tag in AWS ECR
#!/usr/bin/env bash
# Example:
# ./find-ecr-image.sh foo/bar mytag
if [[ $# -lt 2 ]]; then
echo "Usage: $( basename $0 ) <repository-name> <image-tag>"
exit 1
fi
IMAGE_META="$( aws ecr describe-images --repository-name=$1 --image-ids=imageTag=$2 2> /dev/null )"
@Swader
Swader / odgovor.md
Last active December 11, 2018 17:57
What it's like to live in Croatia

Life in Croatia

As with any place, there are a few pros and a number of cons. Most of my experiences are derived from living and working in the country. A bird’s eye view if you like.

At a high level, to continue with the bird theme, Croatia has an attractive climate with four distinct seasons. There is a proper coast line with plenty to choose from in terms of places to go and hang out during the summer. It’s countryside quite beautiful. The country’s infrastructure generally works due almost entirely to EU largesse. Commercially there is a reasonably educated work force that is sadly bereft of opportunity. Relationships with Croats is generally transactional and individual success is punished.

Economics and Business

Taxation rate is a whopping 61% with employers having to add an additional 17%. The effective impact of this means, with the best part of 80% going to income based taxation, there is a thriving cash or black market system and it functions as a massive disincentive for local companies to

#/bin/bash
# kill dev server
lsof -i :8081 | awk 'NR!=1 {print $2}' | xargs kill
# In gnome-terminal, go to Edit -> Profile Preferences -> Title. Click the Command tab. Select Hold the terminal from the drop-down menu labelled When command exits. Name the profile hold-terminal
echo "Starting Android Emulator"
AVD_NAME=$1
@ericnormand
ericnormand / 00 Description.md
Last active November 4, 2022 14:36
320 - PurelyFunctional.tv Newsletter - Puzzle - Remove nth element

remove the nth element from a list

Clojure's two main sequences, lists and vectors, do not easily let you remove an item from the collection when that item is in the middle of the sequence. Sometimes we need to do that. Write a function remove-at that removes the element at position n from a sequence.

(remove-at 3 [1 2 3 4 5 6])
; => (1 2 3 5 6)

Make this robust. You'll have to make some hard design decisions like how to handle the empty sequence, how to handle out-of-bounds n, and more.