Skip to content

Instantly share code, notes, and snippets.

View eliascotto's full-sized avatar

Elia Scotto eliascotto

View GitHub Profile
@danownsthisspace
danownsthisspace / stratch.clj
Created November 21, 2021 15:05
A function wrapper that ensures that a function can only be called once
(ns scratch.core)
(defn say-hi [username]
(let [s (str "hello, " username)]
(Thread/sleep (rand 100))
(println s)
s))
(comment (say-hi "Steve"))
@didibus
didibus / clojure-right-tool.md
Last active July 10, 2024 04:30
When is Clojure "the right tool for the job"?

My answer to: https://www.reddit.com/r/Clojure/comments/pcwypb/us_engineers_love_to_say_the_right_tool_for_the/ which asked to know when and at what is Clojure "the right tool for the job"?

My take is that in general, the right tool for the job actually doesn't matter that much when it comes to programming language.

There are only a few cases where the options of tools that can do a sufficiently good job at the task become limited.

That's why they are called: General-purpose programming languages, because they can be used generally for most use cases without issues.

Let's look at some of the dimensions that make a difference and what I think of Clojure for them:

@viebel
viebel / godel-escher-bach-g-fractal.cljs
Last active August 18, 2021 01:48
Godel Escher Bach - G fractal from Chapter 5
;; Godel Escher Bach - G fractal from Chapter 5
(set!
(.-innerHTML js/klipse-container)
"<canvas style='width:100%; height:100%'></canvas>")
(def canvas (aget (js/document.getElementsByTagName "canvas") 0))
(set! (.-height canvas) (.-innerHeight js/window))
(def ctx (.getContext canvas "2d"))
@mickeypash
mickeypash / gist:b0b22ab84495fe4b033895a79dd78468
Last active May 19, 2024 07:26
George Hotz - talking hour - 2020-08-31
@TakesxiSximada
TakesxiSximada / .gitignore
Last active January 8, 2023 13:04
change-case.el - Transform a string between camelCase, PascalCase, snake_case, kebab-case, doted.case and others by Emacs Lisp.
*.elc
@wpm
wpm / poll.js
Last active November 14, 2019 09:59
Javascript Polling with Promises
var Promise = require('bluebird');
/**
* Periodically poll a signal function until either it returns true or a timeout is reached.
*
* @param signal function that returns true when the polled operation is complete
* @param interval time interval between polls in milliseconds
* @param timeout period of time before giving up on polling
* @returns true if the signal function returned true, false if the operation timed out
*/
@JungeAlexander
JungeAlexander / import-package-from parent.py
Created November 27, 2014 17:22
Import modules from parent folder in Python
# From http://stackoverflow.com/a/11158224
# Solution A - If the script importing the module is in a package
from .. import mymodule
# Solution B - If the script importing the module is not in a package
import os,sys,inspect
current_dir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
parent_dir = os.path.dirname(current_dir)
sys.path.insert(0, parent_dir)
@john2x
john2x / 00_destructuring.md
Last active July 9, 2024 01:38
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

@chaitanyagupta
chaitanyagupta / _reader-macros.md
Last active May 19, 2024 19:25
Reader Macros in Common Lisp

Reader Macros in Common Lisp

This post also appears on lisper.in.

Reader macros are perhaps not as famous as ordinary macros. While macros are a great way to create your own DSL, reader macros provide even greater flexibility by allowing you to create entirely new syntax on top of Lisp.

Paul Graham explains them very well in [On Lisp][] (Chapter 17, Read-Macros):

The three big moments in a Lisp expression's life are read-time, compile-time, and runtime. Functions are in control at runtime. Macros give us a chance to perform transformations on programs at compile-time. ...read-macros... do their work at read-time.

@alandipert
alandipert / maptemplate.md
Created January 30, 2013 00:28
ClojureScript macros: kinda, sorta, not really.

ClojureScript macros: kinda, sorta, not really.

ClojureScript does not have a standalone macro system. To write ClojureScript macros, one must write them in Clojure and then refer to them in ClojureScript code. This situation is workable, but at a minimum it forces one to keep ClojureScript code and the macros it invokes in separate files. I miss the locality of regular Clojure macros, so I wrote something called maptemplate that gives me back some of what I miss. The technique may be useful in other scenarios.

Problem

Suppose you're wrapping functionality in another namespace or package so that you can have your own namespace of identically named but otherwise decorated functions:

ClojureScript: