Skip to content

Instantly share code, notes, and snippets.

View nischalshrestha's full-sized avatar
🔨

Nischal Shrestha nischalshrestha

🔨
View GitHub Profile
@nischalshrestha
nischalshrestha / main.cs
Created April 18, 2018 01:19
New Public Gist
using System.Linq;
using ServiceStack;
using ServiceStack.Text;
public class GithubRepository
{
public string Name { get; set; }
public string Description { get; set; }
public string Url { get; set; }
public string Homepage { get; set; }
@nischalshrestha
nischalshrestha / regex_df.py
Last active April 5, 2019 21:24
regex for dataframe syntax
import sys
import re
# construct regex here and export python regex: https://www.debuggex.com
# TODO make regex ignore white space where it doesn't matter
# first case: df[['col'...]] <-> df[c('col'...)]
list_re = "\\s{0,}\\[\\s{0,}('\\w{1,}'){1,}\\s{0,}(,\\s{0,}'\\w{1,}'){0,}\\s{0,}\\]"
list_vars = re.compile(list_re)
@nischalshrestha
nischalshrestha / pandas_parser.py
Last active April 5, 2019 21:34
Lark example
# dependencies:
# - Python3.6
# - Lark: pip install lark-parser
import sys
import os.path
from lark import Lark, Transformer, Visitor
from lark import Tree
# https://github.com/lark-parser/lark/blob/master/lark/grammars/common.lark
"""
Source: https://stackoverflow.com/questions/19726663/how-to-save-the-pandas-dataframe-series-data-as-a-figure/39358752#39358752
Modification: Saved returned plot and created figure to save as pdf
"""
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import six
df = pd.DataFrame()
@nischalshrestha
nischalshrestha / in-c-by-terry-riley.markdown
Created December 12, 2019 22:25
“In C” by Terry Riley

“In C” by Terry Riley

This only performs well in Google Chrome, Firefox, and Safari.

“In C” is a musical piece intended to be played by a variable amount of performers. The piece is divided into 53 segments that are to be played, “consecutively with each performer having the freedom to determine how many times he or she will repeat each pattern before moving on to the next.”

Performers are expected to stay within two or three patterns of each other. Once each performer is on the last segment, each performer repeats the last pattern until everyone arrives there, and then they each drop out one by one. This performance is truncated from the preferred 45-90 seconds per segment to 7.5-15 seconds per segment if played at 120 bpm.

On the right, you will see each performer and their current segment as well as a tempo control. In the visualization, each color corresponds to the note being played with red being “C”. The x axis and width of the note are r

@nischalshrestha
nischalshrestha / dark_ambient.rb
Created April 27, 2020 06:53
Sonic Pi: Dark ambient
# ambient 0
live_loop :slow_drone do
with_fx :bitcrusher, cutoff: 40 do
with_fx :gverb, room: 40 do
with_fx :echo, decay: 20 do
with_fx :echo, decay: 1, mix: 1 do
with_synth :saw do
play (scale :c2, :major_pentatonic).choose,
amp: 1,
# 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
---
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
@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