Skip to content

Instantly share code, notes, and snippets.

View crosstyan's full-sized avatar

Crosstyan crosstyan

View GitHub Profile
@michalmarczyk
michalmarczyk / letrec2.clj
Created May 16, 2014 19:57
letrec for Clojure using tools.macro's symbol-macrolet
;(use '[clojure.tools.macro :only [symbol-macrolet]])
(defmacro letrec
"Like let, but the bindings may be mutually recursive, provided that
the heads of all values can be evaluated independently.
This means that functions, lazy sequences, delays and the like can
refer to other bindings regardless of the order in which they
appear in the letrec form."
[bindings & body]
@denji
denji / swap-commands.txt
Created July 3, 2014 08:24 — forked from dan-palmer/swap-commands.txt
OSX swap disable/enable launchd
# check swap usage
sysctl vm.swapusage
# disable encrypted swap - SNOW LEOPARD
sudo defaults write /Library/Preferences/com.apple.virtualMemory UseEncryptedSwap -boolean no
# disable encrypted swap - LION
sudo defaults write /Library/Preferences/com.apple.virtualMemory DisableEncryptedSwap -boolean yes
# disable swap
@jnovack
jnovack / README.md
Last active September 23, 2025 16:12
Opening up mosh in firewalld using firewall-cmd

Mosh (mobile shell) is a gift from the Gods(tm). Anyone with spotty internet or wireless connection has suffered the pain of a lost SSH session. Sure, one can fire up screen (or tmux as the kids are using these days), but that's an extra step and you are still using the SSH protocol.

I'm not here to tout the benefits of Mosh, you came here to open it up in your firewall.

  1. Create the following file as /etc/firewalld/services/mosh.xml
  2. firewall-cmd --add-service=mosh --permanent
  3. firewall-cmd --reload

If you tend to have a lot of sessions (not recommended), you can increase the ports, but the default should be fine for most applications.

@superfunc
superfunc / gist:36242904c2b7b10b0bd5
Created October 29, 2014 06:58
Maybe type in Nim
# An implementation of the Maybe monad for Nim
# This implements the traditional operations, bind(called chain)
# and return(called box) as well as a few useful operators for
# cleaning up usage of the monad. Also implemented the functor
# operation fmap(called map) which allows a procedure to be called
# on a wrapped value
type
Maybe*[T] = object
case valid*: bool

Writing Functionally Pure Code

Is all my code going to be pure?

Nope. No program can be composed 100% of pure code because every program must do I/O work, which is inherently stateful. Most programs also need to carry around some amount of internal state, to one degree or another. The goal of functional programming, then, is to maximize the proportion of pure code to impure code in your program.

Pure vs. Impure

What does it mean for data and code to be pure? The short answer is that pure things are immutable, but this is not quite accurate: all pure things are immutable, but not all immutable things are pure. Pure things are not only unmodifiable but also definitional.

How Clojure Code Becomes a Running Program

Lisp, the original high-level language, introduced a long list of features common in languages today, including dynamic typing, interpretation, and garbage collection. The original Lisp language is long gone, but it had many imitators, which we call 'dialects' of Lisp. Clojure, introduced in 2007, is the first Lisp dialect to gain wide usage in three decades.

Though Lisp features have been co-opted by many other languages, what still distinguishes Lisp dialects from all other languages is how Lisp dialects translate source code into running programs. In non-Lisp languages, the code translation process has two primary steps:

  1. lexing (a.k.a. tokenization) and parsing
  2. code generation (compilation or interpretation)
@coltnz
coltnz / clojure-repl-log-level-logback
Created February 12, 2015 00:28
set clojure tools logging level in repl (logback version)
; in user.clj
(:import [org.slf4j LoggerFactory]
[ch.qos.logback.classic Logger Level]
(defn set-log-level! [level]
(.. (LoggerFactory/getLogger org.slf4j.Logger/ROOT_LOGGER_NAME)
(setLevel (Level/valueOf (.toUpperCase (name level))))))
@magnetikonline
magnetikonline / README.md
Last active October 31, 2025 20:11
NSSM - the Non-Sucking Service Manager cheatsheet.
@CMCDragonkai
CMCDragonkai / haskell_numeric_typeclasses.md
Last active November 19, 2025 01:57
Haskell: Numeric Typeclasses - How numbers work!

Numeric Typeclasses - How numbers work!

Numbers in Haskell are typed of course. They also exist as instances of a numeric typeclass hierarchy. I was confused with converting and working with numbers of different types, and not being sure which functions were polymorphic and could work with different numeric types. So I created a little diagram. Do note that the typeclass hierarchy of Haskell actually does somewhat follow the hierarchy of numbers in Math.

@Sebb767
Sebb767 / Readme.md
Created August 6, 2015 01:22
Escape The Matrix (Dark Web Article)

This is the famous escape the matrix article from the hidden wiki. Since most mirrors are down and on the hidden wiki itself, the first chaper was replaced with a bitcoin scam, I thought I repost this here. Copyright goes to the original author and I'm not stating any opinion on this text except that it may or may not be an interesting read ;)

The .txt version is taken from here (there's also an intepretation where that came from), the markdown version was converted via some regexes by, well, me.

Have fun :)