Program: fibonacci.cr
def fibonacci(n)
return n if n < 2
fibonacci(n - 1) + fibonacci(n - 2)
#!/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 |
# 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 |
# 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 |
#!/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: |
// ============================================================================= | |
// 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. |
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?)
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"