Skip to content

Instantly share code, notes, and snippets.

@conundrumer
conundrumer / iterators.rs
Created November 22, 2016 21:16
returning iterators in rust
#![feature(conservative_impl_trait)]
// without impl trait or box
use std::iter::{ FlatMap, Map, Enumerate, Iterator };
use std::str::Chars;
type GetIterFnType = Fn((usize, char)) -> Option<char>;
type IdentityType = Fn(Option<char>) -> Option<char>;
type GetIterType<'a> = FlatMap<Map<Enumerate<Chars<'a>>, &'static GetIterFnType>, Option<char>, &'static IdentityType>;
const GET_ITER_FN: &'static GetIterFnType = &|(i, x)| if i % 2 == 0 { Some(x) } else { None };
@conundrumer
conundrumer / yt-ad-buster.js
Last active May 13, 2020 16:26
yt-ad-buster.js: Prevents a YouTube video from being used as an ad by toggling visibility when views from ad are detected.
/* yt-ad-buster.js: Prevents a YouTube video from being used as an ad by toggling visibility when views from ad are detected.
Usage:
Go to video "Details" page and run this script.
To stop, focus on main page and press Escape.
When running, the main page header should turn RED.
When stopped, the header should turn light blue.
If the main page is hidden in a tab, the automation may run slower.
If it runs too fast, YouTube will rate limit with 429 RESOURCE_EXHAUSTED errors.
*/
class AdBusterRunner {
@conundrumer
conundrumer / yt-autotoggler.js
Last active April 16, 2020 16:54
Periodically toggles visibility of a YouTube video.
/* yt-autotoggler.js: Periodically toggles visibility of a YouTube video.
Usage:
Go to video "Details" page and run this script. Requires pop-ups.
To stop, focus on main page and press Escape.
When running, the main page header should turn violet.
When stopped, the headers should turn light blue.
If the main page is hidden in a tab, the automation may run slower.
If `baseInterval` is less than 4 seconds, YouTube will rate limit with 429 RESOURCE_EXHAUSTED errors.
*/
async function run() {
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
function run() {
return _run.apply(this, arguments);
}
function _run() {
_run = _asyncToGenerator(function* () {
<b>test</b>
function cf (ps) {
ps = [...ps].reverse()
let x0 = 1
let i = 0
while (i++ < 10000000) {
let x1 = x0
for (let p of ps) {
x1 = p + 1 / x1
@conundrumer
conundrumer / lr-dragon-curve.js
Created August 7, 2018 01:02
generate a dragon curve
function* dragonCurveGen(startPoint, endPoint, maxIterations, left) {
const M = {
mult: (m, v) => [
m[0][0] * v[0] + m[0][1] * v[1],
m[1][0] * v[0] + m[1][1] * v[1]
],
minus: (u, v) => [u[0] - v[0], u[1] - v[1]],
plus: (u, v) => [u[0] + v[0], u[1] + v[1]],
left: [[0.5, -0.5], [0.5, 0.5]],
function sumNaive (n, acc = 0) {
if (n === 0) {
return acc
}
return sumNaive(n - 1, acc + n)
}
// console.log(sumNaive(1000))
// console.log(sumNaive(100000))
@conundrumer
conundrumer / speedometer.jsx
Created January 2, 2018 02:17
lrjs speedometer
import React from 'react'
import Vector from 'core/Vector'
function angleTo (u, v) {
return Math.atan2(u.cross(v), u.dot(v))
}
export default function Speedometer ({rider, prevRider, toolbarsOpen}) {
let style = {position: 'absolute', top: toolbarsOpen ? 40 : 0, right: 0, padding: 8, textAlign: 'right', fontFamily: 'monospace', backgroundColor: 'rgba(255,255,255,0.8)'}
let avgPos = rider.points.reduce((acc, {pos}) => acc.add(pos), new Vector(0, 0)).divS(rider.points.length)
@conundrumer
conundrumer / lrjs.v0.9.7.update.md
Last active December 28, 2017 21:21
documentation of added functionalities of lrjs v0.9.7

line tool

given a line being drawn:

  • +shift: angle lock (to the line that the drawn line is snapped to)
  • +shift+mod: length snap (to nearest power of 2)
  • +shift+mod+alt: length snap + angle snap

selection tool