Skip to content

Instantly share code, notes, and snippets.

View nischalshrestha's full-sized avatar
🔨

Nischal Shrestha nischalshrestha

🔨
View GitHub Profile
@nischalshrestha
nischalshrestha / night_owl.rb
Created February 27, 2021 19:03
Night owl midi jam
# "night owl" jam
# sonic pi version: v3.2.1
with_fx :reverb, room: 1 do
live_loop :midi_piano do
use_real_time
note, velocity = sync "/midi:midi_fighter_64:0:3/note_on"
with_fx :flanger, wave: 0, decay: 0, delay: 0, max_delay: 0 do
synth :pretty_bell, note: note - 12
synth :pluck, note: note - 12, attack: 0, coef: -0.5, sustain: 0, amp: (velocity / 127.0)
synth :pluck, note: note, attack: 0, coef: 0.1, sustain: 0, amp: (velocity / 127.0)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
<style id="jsbin-css">
body {
padding: 10px;
}
@nischalshrestha
nischalshrestha / coffeecookiecrumble.rb
Last active September 12, 2020 04:30
Electronic disco beat
#| electro-disco (4/4)
use_bpm 100
note_value = 0.5 # eighth notes
beats = 8
# beat on/off patterns
hh = spread(8, beats) # hit every beat
sn = spread(2, beats).rotate(-2) # hit 2nd and 4th beat
b = spread(1, beats) # hit 1st and 2nd beat
bd1 = spread(1, 4) * 2 # custom for bass drum
bd2 = spread(1, 8 * 2).rotate(1) # custom for bass drum
@nischalshrestha
nischalshrestha / weird.R
Created July 23, 2020 02:09
R scrambled argument order
library(rlang)
fun <- function(x = 3, y, z = 1) {
paste(x, y, z)
}
# default arguments and regular argument order can be scrambled
# yet produce the same call
@nischalshrestha
nischalshrestha / get_raw_chunks.R
Last active September 9, 2020 23:41
Raw knitr chunks (inside hook context)
# test file
sample_chunk <- "
```{r hello, testing=as.logical(1), another=1 + 1}
1 + 1
```"
file = "sample.Rmd"
writeLines(sample_chunk, con = file)
foo_hook <- function(before, options, envir) {
# note: this returns raw knitr chunks in list format
# has attribute of "chunk_opts"
@nischalshrestha
nischalshrestha / horror.rb
Last active July 11, 2020 07:35
Sonic Pi Horror
# lfo for sines
lfo0 = (range 0, 2, 0.25).mirror
lfo1 = (range 0, 1, 0.025).mirror
# lfo for panning
lfo2 = (range -1, 1, 0.125).mirror
# lfos for bd_haus (dark-side of the beat)
lfo3 = (range 0.25, 0.5, 0.025).mirror
lfo4 = (range 0.5, 3, 0.125).mirror
# let's get wonky with it! slow, slow, slow steps
lfo5 = (range 1, 8, 0.005).mirror
---
title: "Python exercises"
author: "Nischal Shrestha"
# output: library(devtools); library(here); load_all(here()); learnr::tutorial # use this when using a local learnr
output: learnr::tutorial
runtime: shiny_prerendered
---
```{r setup, include=FALSE}
# R related
# Electrotribal dance
live_loop :bass_drums do
amp = 0.0
if (spread 7, 8).reverse.tick
sample :bd_haus, rate: 1, attack: 0.01, release: 0.25, amp: amp
sleep 0.5
else
sample :bd_haus, rate: rrand_i(1, 3), attack: 0.025, sustain: 0.5, release: 0.1, amp: amp + 1
sleep 0.09
@nischalshrestha
nischalshrestha / ambient1.rb
Created May 10, 2020 04:51
Sonic Pi: Ambient 1
##| Ambient 1
with_fx :reverb, room: 0.8, mix: 0.6 do
live_loop :deep_saws do
use_synth :saw
amp = 0
release = rrand_i(5, 8)
attack = rrand(0.8, 3.0)
with_fx :lpf, cutoff: 80 do
@nischalshrestha
nischalshrestha / arps.rb
Last active October 4, 2023 03:18
Sonic Pi Jams
##| Recreating a Colin Bender arppegio pattern from lockdown day 40
##| Cm, Abmaj, Ebmaj, Bdim
##| intervals for readability
root = 0
second = 1
third = 2
fourth = 3
fifth = 4
eighth = 7