Skip to content

Instantly share code, notes, and snippets.

@substack
substack / xin
Created Sep 16, 2020
xinput wrapper for x395 with touchscreen
View xin
#!/bin/bash
getid() {
if echo "$1" | grep -E '^[0-9]+$' >/dev/null; then
echo "$1"
elif test "$1" = touchpad -o "$1" = pad; then
echo $(xinput | grep -i touchpad | sed -E 's/.*\bid=([0-9]+)\b.*/\1/')
elif test "$1" = touchscreen -o "$1" = "screen"; then
echo $(xinput | grep -i 'touch system' | sed -E 's/.*\bid=([0-9]+)\b.*/\1/')
elif test "$1" = trackpoint -o "$1" = pointer -o "$1" = point; then
echo $(xinput | grep -i trackpoint | sed -E 's/.*\bid=([0-9]+)\b.*/\1/')
@substack
substack / yiq.js
Last active Oct 4, 2020
yiq modulation and demodulation for ntsc chrominance
View yiq.js
// yiq modulation + demodulation example
// written in a way that can be ported to a shader
// with only 3 texture lookups
const carrierHz = 3_579_545
const multiple = 8
const sampleRate = carrierHz*multiple
const sampleCount = Math.floor(1/30*sampleRate) // 1 frame
var signal = (function generate () {
View error
Compiling eyros v2.0.0 (/home/substack/projects/peermaps/eyros)
error[E0277]: `std::future::from_generator::GenFuture<[static generator@eyros::DB::<S, U, P, V>::query::{{closure}}#0::{{closure}}#1 0:eyros::QueryStream<eyros::mix::Mix3<f32, f32, u64>, u32> for<'r, 's> {std::future::ResumeTy, &'r mut eyros::QueryStream<eyros::mix::Mix3<f32, f32, u64>, u32>, eyros::QueryStream<eyros::mix::Mix3<f32, f32, u64>, u32>, impl std::future::Future, ()}]>` cannot be unpinned
--> tests/mix3.rs:71:35
|
71 | while let Some(result) = stream.next().await {
| ^^^^ within `impl std::future::Future`, the trait `std::marker::Unpin` is not implemented for `std::future::from_generator::GenFuture<[static generator@eyros::DB::<S, U, P, V>::query::{{closure}}#0::{{closure}}#1 0:eyros::QueryStream<eyros::mix::Mix3<f32, f32, u64>, u32> for<'r, 's> {std::future::ResumeTy, &'r mut eyros::QueryStream<eyros::mix::Mix3<f32, f32, u64>, u32>, eyros::QueryStream<eyros::mix::Mix3<f32, f32, u64>, u32
View error
error: future cannot be sent between threads safely
--> src/data.rs:35:80
|
35 | async fn batch (&mut self, rows: &Vec<&(P::Range,u64)>) -> Result<u64,Error> {
| ________________________________________________________________________________^
36 | | if rows.len() == 1 { // use existing address
37 | | Ok(rows[0].1)
38 | | } else { // combine addresses into a new block
... |
50 | | }
View errors
error[E0597]: `self` does not live long enough
--> src/lib.rs:617:24
|
617 | let p = Box::pin(self.get_next());
| ^^^^ borrowed value does not live long enough
618 | self.pending = Some(p);
| - cast requires that `self` is borrowed for `'static`
...
625 | }
| - `self` dropped here while still borrowed
View errors
error[E0277]: `std::future::from_generator::GenFuture<[static generator@src/main.rs:1:1: 1:1 f:_, buf:_ _]>` cannot be unpinned
|
= note: required because it appears within the type `impl std::future::Future`
error[E0599]: no method named `next` found for struct `TrySource<&[u8], impl std::future::Future>` in the current scope
|
= note: the method `next` exists but the following trait bounds were not satisfied:
`TrySource<&[u8], impl std::future::Future>: futures_core::stream::Stream`
which is required by `TrySource<&[u8], impl std::future::Future>: async_std::stream::stream::StreamExt`
@substack
substack / collisions.js
Created Apr 28, 2020
calculate unique sequences
View collisions.js
var { randomBytes } = require('crypto')
var N = 10_000
var keys = build(N)
// print the 10 longest sequences
var sequences = []
for (var i = 0; i < N; i++) {
var n = Math.max(4, unambiguous(keys, keys[i]))
sequences.push({ seq: keys[i].slice(0,n), index: i })
View match.js
var m = /^\/ban\s+(\S+)\s*(.*)$/.exec(process.argv.slice(2).join(' '))
var obj = {}
if (m) {
obj.user = m[1]
var str = m[2]
while (str.length > 0) {
if (m = /^\s*\bfor\s+(\d+)\s+(\S+)(.*)/.exec(str)) {
obj.duration = {
quantity: Number(m[1]),
unit: m[2]
@substack
substack / const.rs
Last active Apr 11, 2020
const integer log implementation in rust
View const.rs
#![feature(const_if_match,const_loop,const_int_pow)]
use std::mem::size_of;
type T = u128;
const fn log2(x: T) -> Option<T> {
if x <= (0 as T) {
None
} else {
Some(logb2(x))
@substack
substack / bench.rs
Last active Apr 11, 2020
rust integer log benchmarks recursive vs iterative
View bench.rs
#![feature(test)]
use std::mem::size_of;
use std::ops::{Div,Add,Mul};
extern crate test;
use test::Bencher;
trait IntegerLog {
fn log2(&self) -> Option<Self> where Self: Sized;
fn log_new(&self, base: Self) -> Option<Self> where Self: Sized;
You can’t perform that action at this time.