This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import board | |
import usb_midi | |
import adafruit_midi | |
from analogio import AnalogIn | |
from adafruit_midi.control_change import ControlChange | |
# MIDI CC knob controller example for Raspberry Pi Pico |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "app/strings.rb" | |
def undo_last_stroke(args) | |
args.state.counts.pop | |
stroke = args.state.counts.pop | |
args.state.commands.slice!(0 - stroke, stroke) if stroke | |
end | |
def tick(args) | |
args.state.help_layer ||= :shown |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cmath> | |
#include <cstdio> | |
double smoothstep(double low, double high, double factor){ | |
auto k = std::fmin(1, std::fmax(0, (factor - low)/(high - low))); | |
return k*k*(3-2*k); | |
} | |
int main(){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def is_prime(n): | |
"""A very basic implementation of the Miller-Rabin primality test.""" | |
#from Wikipedia: "if n < 341,550,071,728,321, it is enough to test a = 2, 3, 5, 7, 11, 13, and 17." | |
small_primes = {2,3,5,7,11,13,17} | |
if n in small_primes: return True | |
if n < 2 or n & 1 == 0: return False | |
r, d = (0, n-1) | |
while (d & 1) == 0: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <algorithm> | |
#include <array> | |
template <typename T> | |
constexpr std::array<char, sizeof(T)> into_bytes(const T& t){ | |
std::array<char, sizeof(T)> bytes; | |
std::copy( reinterpret_cast<const char*>(&t), reinterpret_cast<const char*>(&t) + sizeof(t), bytes.begin() ); | |
return bytes; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//needed to make friendly for map function, which expects function taking dereferenced string index as argument | |
function charCodeOfChar(character){ | |
return character.charCodeAt(0); | |
} | |
//String's prototype function will give weird UTF-16 literal output otherwise | |
function charFromCharCode(charCode){ | |
return String.fromCharCode(charCode); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require 'vendor/autoload.php'; | |
use Symfony\Component\Stopwatch\Stopwatch; | |
/** | |
* @param callable $callable is a function or functor callable with parentheses. | |
* @param array ...$args is the argument list which will be supplied to the $callable function. | |
* @return float|int which represents the time elapsed in the function called, in milliseconds. | |
*/ | |
function benchmarker(Callable $callable, ...$args){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <vector> | |
#include <iostream> | |
#include <iterator> | |
#include <algorithm> | |
int main() | |
{ | |
std::vector<int> v {7,4,1,8,5,2,9,6,3}; | |
std::copy(v.begin(), v.end(), std::ostream_iterator<int>(std::cout , " ")); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//point inversion | |
#include <vector> | |
#include <iostream> | |
struct Point { int x, y; }; | |
struct Line { Point petal, center; }; | |
//reflects Point 'mover' across another Point 'focus'. | |
//'focus' is the midpoint of 'mover' and the return value. | |
Point invert_point(const Point mover, const Point focus){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//this function converts any member of enum of any underlying type to that type. | |
//Effective Modern C++ by Scott Meyers. See item 10 | |
template <typename E> | |
constexpr auto to_underlying(E e) noexcept | |
{ | |
return static_cast<std::underlying_type_t<E>>(e); | |
} |
NewerOlder