This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# See also andrewchambers/janet-sh for a more complete (and awesome) solution: | |
# https://acha.ninja/blog/dsl_for_shell_scripting/ | |
# | |
# Source: https://github.com/janet-lang/jpm/blob/07b0c18daf75cfdf098eff5526a17ad0436e3dc0/jpm/shutil.janet#L123-L137 | |
(defn exec-slurp | |
"Read stdout of subprocess and return it trimmed in a string." | |
[& args] | |
(when (dyn :verbose) | |
(flush) | |
(print ;(interpose " " args))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn primes-before | |
"Gives all the primes < limit" | |
[limit] | |
(assert (int? limit)) | |
# Janet has a buffer type (mutable string) which has easy methods for use as bitset | |
(def buf-size (math/ceil (/ (+ 1 limit) 8))) | |
(def is-prime (buffer/new-filled buf-size (bnot 0))) | |
(buffer/bit-clear is-prime 0) | |
(buffer/bit-clear is-prime 1) | |
(for n 0 (math/ceil (math/sqrt limit)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ported from this Python code: https://gist.github.com/Techcable/c411b3a550e252b1fd681e1fc1734174 | |
# | |
# Based on R. Sedgewick's Algorithms, Chapter 2.4 | |
(defn swap [l a b] | |
(let [aval (get l a) bval (get l b)] | |
(put l a bval) | |
(put l b aval))) | |
(defn heap-sort [l] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import operator | |
def swap(l: list, i: int, j: int): | |
assert i < len(l), i | |
assert j < len(l), j | |
l[i], l[j] = l[j], l[i] | |
def heap_sort(l: list) -> list: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import floor, log10 | |
import sys | |
WORDS = { | |
0: 'zero', | |
1: 'one', | |
2: 'two', | |
3: 'three', | |
4: 'four', | |
5: 'five', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
from sys import getsizeof, stderr | |
from itertools import chain | |
from collections import deque | |
try: | |
from reprlib import repr | |
except ImportError: | |
pass | |
def total_size(o, handlers={}, verbose=False): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This class has one method: nextPermutation | |
* | |
* It finds the next permutation of the specified integer values | |
* | |
* Credit to Rosen's discrete structures book for the algorithm. | |
*/ | |
public class Permutations { | |
/** | |
* Returns the next permutation of the specified values, in lexographic order |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* See github gist: | |
* https://gist.github.com/Techcable/47ddd3750adc5b9df824b6b3986eb251 | |
*/ | |
#include <string> | |
#include <cstdlib> | |
#include <optional> | |
#include <vector> | |
#include <fstream> | |
#include <sstream> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BEGIN MESSAGE. | |
EAfLPl3xKameGpN Vmhi4ObNWYpkd5N QfiQsMMYG0KW1UK sEERbXJe8AM4BcQ | |
ksZbUKC4rZnfVZ8 ikEAjYL02ReTCKq 6Xr2MZHgg6epqBl xRzC4RYtZr5n3NM | |
baM9xX9kTCbyq4k mBiAsRm2o1koNn0 VDNWKYed09jJ5Rh zbK8pAVSYFOvR0b | |
7S5hXYJGXUVU0md riqrfDQFntLzGGG F0quO29HFxl. | |
END MESSAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/etc/.pwd.lock | |
/etc/.updated | |
/etc/adjtime | |
/etc/ca-certificates/ | |
/etc/dhcpcd.duid | |
/etc/group | |
/etc/group.pacnew | |
/etc/gshadow- | |
/etc/ld.so.cache | |
/etc/locale.gen.pacnew |