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
tsujp / 00_readme.md
Created July 17, 2022 12:31 — forked from p4bl0-/00_readme.md
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
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 http://stackoverflow.com/questions/1218390/what-is-your-most-productive-shortcut-with-vim/1220118#1220118

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
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
tsujp / ANSI.md
Created July 5, 2022 07:55 — forked from fnky/ANSI.md
ANSI Escape Codes

ANSI Escape Sequences

Standard escape codes are prefixed with Escape:

  • Ctrl-Key: ^[
  • Octal: \033
  • Unicode: \u001b
  • Hexadecimal: \x1B
  • Decimal: 27
@tsujp
tsujp / hack.sh
Created July 1, 2022 09:58 — forked from DAddYE/hack.sh
OSX For Hackers
#!/bin/sh
##
# This is a script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# Run in interactive mode with:
# $ sh -c "$(curl -sL https://raw.github.com/gist/2108403/hack.sh)"
#
# or run it without prompt questions:
@tsujp
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 https://distfiles.macports.org/MacPorts/MacPorts-2.5.3.tar.bz2
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
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 golang.org/dl/go"$@"@latest
$gobindir/go"$@" download
@tsujp
tsujp / random_password.sh
Created June 29, 2022 13:19 — forked from pmarreck/random_password.sh
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
tsujp / Fibonacci_OCaml_Crystal_Go.md
Created June 29, 2022 10:44 — forked from s0kil/Fibonacci_OCaml_Crystal_Go.md
Crystal vs Ocaml vs Go Fibonacci Benchmark

Fibonacci - Crystal vs OCaml vs Go

Crystal

Program: fibonacci.cr

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