Skip to content

Instantly share code, notes, and snippets.

View crosstyan's full-sized avatar

Crosstyan crosstyan

View GitHub Profile

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.

@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
@jnovack
jnovack / README.md
Last active November 18, 2024 15:59
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.

@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
@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]
@samvasko
samvasko / makefile
Created April 7, 2014 09:37
Makefile for building keil projects
# Makefile for building keil projects
KEIL=wine "/home/bliker/.wine/drive_c/Keil/UV4/UV4.exe"
TMP=/tmp/keil.out
NULL=/dev/null
# Will prevent it from exiting even when somehing failied
build:
-@$(KEIL) -j0 -b -o $(TMP) *.uvproj 2> $(NULL);
@cat $(TMP)
@polarity
polarity / javascript.partial.markdown
Last active July 10, 2024 21:18
# Functional Programming Javascript: using Partials

Functional Programming Javascript: using Partials

Partials are basically functions that return functions with some already predefined arguments and need some arguments to be completed. Let's say you have a function with several arguments to be set, but you don't want to set the majority of arguments over and over again because you need it more than once.

# my useless function to write something to the dom
function writeSomethingToDom(element, content){
	element.append(content);
}

# use the function repeatedly 
@Starefossen
Starefossen / vim-cheats.md
Last active April 19, 2025 09:10
My vim cheat sheet for working with tabs and window splits.

Tabs

New Tab

  • :tabnew - new blank tab
  • :tabedit [file] - open file in tab

Cursor Movement

  • gt (:tabn) - next tab
@kapkaev
kapkaev / gist:4619127
Created January 24, 2013 09:30
MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Commands that may modify the data set are disabled. Please check Redis logs for details about the error. Resque
$ redis-cli
> config set stop-writes-on-bgsave-error no