Skip to content

Instantly share code, notes, and snippets.

View tsujp's full-sized avatar
Making 1s and 0s work

Jordan Ellis Coppard tsujp

Making 1s and 0s work
View GitHub Profile
tsujp /
Created July 17, 2022 12:31 — forked from p4bl0-/
A complete compiler for a simple language (in less than 150 LoC)

This project is a tiny compiler for a very simple language consisting of boolean expression.

The language has two constants: 1 for true and 0 for false, and 4 logic gates: ! (not), & (and), | (or), and ^ (xor).

It can also use parentheses to manage priorities.

Here is its grammar in BNF format:

expr ::= "0" | "1"

tsujp / grok_vi.mdown
Created July 9, 2022 14:20 — forked from nifl/grok_vi.mdown
Your problem with Vim is that you don't grok vi.

Answer by Jim Dennis on Stack Overflow question

Your problem with Vim is that you don't grok vi.

You mention cutting with yy and complain that you almost never want to cut whole lines. In fact programmers, editing source code, very often want to work on whole lines, ranges of lines and blocks of code. However, yy is only one of many way to yank text into the anonymous copy buffer (or "register" as it's called in vi).

The "Zen" of vi is that you're speaking a language. The initial y is a verb. The statement yy is a simple statement which is, essentially, an abbreviation for 0 y$:

0 go to the beginning of this line. y yank from here (up to where?)

tsujp / kpc_demo.c
Created July 6, 2022 11:35 — forked from ibireme/kpc_demo.c
A demo shows how to read Intel or Apple M1 CPU performance counter in macOS.
// =============================================================================
// XNU kperf/kpc demo
// Available for 64-bit Intel/Apple Silicon, macOS/iOS, with root privileges
// Demo 1 (profile a function in current thread):
// 1. Open directory '/usr/share/kpep/', find your CPU PMC database.
// For M1 (Pro/Max), the database file is '/usr/share/kpep/a14.plist'.
// 2. Select a few events that you are interested in,
// add their names to the `profile_events` array below.
tsujp /
Created July 5, 2022 07:55 — forked from fnky/
ANSI Escape Codes

ANSI Escape Sequences

Standard escape codes are prefixed with Escape:

  • Ctrl-Key: ^[
  • Octal: \033
  • Unicode: \u001b
  • Hexadecimal: \x1B
  • Decimal: 27
tsujp /
Created July 1, 2022 09:58 — forked from DAddYE/
OSX For Hackers
# This is a script with usefull tips taken from:
# Run in interactive mode with:
# $ sh -c "$(curl -sL"
# or run it without prompt questions:
tsujp / install-mac-ports-no-root.bash
Created July 1, 2022 09:38 — forked from daggerok/install-mac-ports-no-root.bash
Install MacPorts 2.5.3 without sudo / root privileges
# install
mkdir ~/macports
cd ~/macports
curl -O
tar xf MacPorts-2.5.3.tar.bz2
cd MacPorts-2.5.3/
./configure --enable-readline --prefix=$HOME/macports --with-no-root-privileges
make && make install
tsujp / go-switch-bash
Created June 30, 2022 06:45 — forked from AnomalRoil/go-switch-bash
The `go switch` function allows you to easily switch you current Go version
# to add to your ~/.bashrc or your ~/.zshrc file. Usage: $ go switch 1.18.1
function go() {
case $* in
switch* )
shift 1
gobindir=$(go env GOBIN)
# adapt to a valid directory at the beginning of your $PATH if you're not on systemd
homebindir=$(systemd-path user-binaries)
go install"$@"@latest
$gobindir/go"$@" download
tsujp /
Created June 29, 2022 13:19 — forked from pmarreck/
Generate random strings or dictionary words in Bash
#!/usr/bin/env bash
# get a random-character password
# First argument is password length
# Can override the default character set by passing in PWCHARSET=<charset> as env
randompass() {
# globbing & history expansion here is a pain, so we store its state, temp turn it off & restore it later
local maybeglob="$(shopt -po noglob histexpand)"
set -o noglob # turn off globbing
set +o histexpand # turn off history expansion
tsujp /
Created June 29, 2022 10:44 — forked from s0kil/
Crystal vs Ocaml vs Go Fibonacci Benchmark

Fibonacci - Crystal vs OCaml vs Go



def fibonacci(n)
  return n if n < 2
  fibonacci(n - 1) + fibonacci(n - 2)
30XG4ydCCDCy1TU aerjE5KOdSpVcVe d3BdA8Vfc2BbPvz 3wtf74afXprZfb5
z2tMC105qULZLzq AopZqPXqfZJTCKq 6Xr2MZHgg6lW1An k9MR21AMRunYgwx
BvC8S3j9D5hzpEu 57p7VzgABIHlKpa 7SBQr.