Skip to content

Instantly share code, notes, and snippets.

View dgellow's full-sized avatar
🐢
Pulu pulu 🏳️‍🌈

Sam El-Borai dgellow

🐢
Pulu pulu 🏳️‍🌈
View GitHub Profile
find . -print0 | while read -d $'\0' file
do
# Statements with $file
done
@dgellow
dgellow / schemeToAudio.swift
Created October 8, 2015 20:27
Some fun with a scheme interpreter and PCM. Call it with `swift AudioFun.playground/Contents.swift "(* t (& (b t 12) 63 (b t 4)))"`
import AVFoundation
var engine = AVAudioEngine()
var player = AVAudioPlayerNode()
var mixer = engine.mainMixerNode
//
//func sineWave(buffer: AVAudioPCMBuffer) -> AVAudioPCMBuffer {
// let sr = Float(mixer.outputFormatForBus(0).sampleRate)
// let n_channels = mixer.outputFormatForBus(0).channelCount
@dgellow
dgellow / audioMicToOutput.swift
Last active May 18, 2017 15:07
Swift playground, redirect mic input to output with delay and reverb. Based on this blog post http://jamiebullock.com/post/89243252529/live-coding-audio-with-swift-playgrounds
import Cocoa
import AVFoundation
// Setup engine and node instances
var engine = AVAudioEngine()
var delay = AVAudioUnitDelay()
var reverb = AVAudioUnitReverb()
var mixer = engine.mainMixerNode
var input = engine.inputNode
var output = engine.outputNode
function Expr(operation, left, right) {
return {op: operation, l: left, r: right};
}
var Add = Expr.bind(null, 'add'),
Mult = Expr.bind(null, 'mult');
function Var(name) {
return {name: name};
}
@dgellow
dgellow / triangle.nim
Last active February 10, 2018 13:59 — forked from allj/triangle.nim
A colorful triangle in nim OpenGL.
import os
import opengl
import glfw/wrapper as glfw
var
win: GLFWwindow
vaoID: GLuint
vboID: GLuint
cboID: GLuint
vertexShaderID: GLuint
proc makeJumpPlayerCommand(player: var Player,
platform: Platform): Command =
var
moveActorCommand = makeMoveActorCommand(player, platform.x,
platform.y)
if not isStrongEnough(player.jumpStrength, platform.altitude):
echo("$1 is not strong enough to jump to the platform" % [player.name])
return nil # <== Error: type mismatch: got (nil) but expected 'Command'
import os
import times
const
speed = 1000
iterator deltat(): int {.closure.} =
var
t0: float = epochTime()
t1: float
@dgellow
dgellow / nim-search.sh
Created July 10, 2015 16:01
Some regexp to find every Nim proc in a file with the given type as first parameter
function nim-procbyfirst {
TYPE_FIRST_ARG=$1
FILE=$2
cat "${FILE}" |
grep -P "^\s*proc\s*(?:\`.+\`|\w+)\*(\[.+\])?\(\w+:\s${TYPE_FIRST_ARG=}" |
grep -oh -P '(?<=proc\s)(?:\`.+\`|\w+).+'
}
# Exemple (system.nim is a local file):
# $ nim-procbyfirst string system.nim
@dgellow
dgellow / crunching.sh
Created July 9, 2015 21:13
MASSIVELY reduce nim binary size
FILE=life.nim
BINARY=life
function compile {
nim c -d:release --passC:-ffast-math --opt:size $FILE
}
function crunch {
strip --strip-all \
-R .note \
@dgellow
dgellow / life.nim
Last active August 29, 2015 14:24
Playing with cellular automation
import os
from strutils import `%`
import libncurses
const
sleepTime = 100
charAlive = "0"
charDead = "_"
nbRow = 30
nbCol = 120