Skip to content

Instantly share code, notes, and snippets.

@rinfz
rinfz / App.tsx
Created September 22, 2022 00:06
React hook form number control
import { useForm, Controller } from "react-hook-form";
const re = /^[-+]?\d*(\.\d*)?$/;
function NumCtrl({ name, onChange, value }: any) {
return <input
name={name}
value={value}
onChange={(e) => {
if (re.test(e.target.value)) onChange(e);
(defn <sqrt [n]
(range 3 (+ (int (Math/sqrt n)) 1)))
(defn prime-inner
[n]
(nil? (some #(= (mod n %) 0) (<sqrt n))))
(defn is-prime? [n]
(cond
(< n 2) false
@rinfz
rinfz / watermark.py
Created July 29, 2021 21:58
watermark images
from PIL import Image, ImageDraw, ImageFont
with Image.open("img.jpeg").convert("RGBA") as base:
font_size = 100
txt = Image.new("RGBA", base.size, (255, 255, 255, 0))
fnt = ImageFont.truetype("/home/mar/.fonts/FiraMono-Regular.ttf", font_size)
d = ImageDraw.Draw(txt)
d.text(
(10, base.size[1] - font_size - 10),
@rinfz
rinfz / foo.rs
Created September 27, 2019 14:37
struct Foo {
data: Vec<f64>,
}
trait FileData {
fn new(raw_data: &[u8]) -> Self;
fn get_data(&self) -> &Vec<f64> {
&self.data
}
fn default_method(&self) -> f64 {
@rinfz
rinfz / a.cu
Last active June 11, 2019 19:31
GDAL + CUDA - (a.cu: basic addition kernel) (b.cu: trig distance from an origin point)
#include <cassert>
#include <cstdio>
#include <vector>
#include <gdal/gdal_priv.h>
__global__ void
vector_add(const int16_t* in, int16_t* out, int num_elements)
{
int i = blockDim.x * blockIdx.x + threadIdx.x;
@rinfz
rinfz / constexpr_crap.cc
Last active March 7, 2019 11:33
constexpr and std::function crap
#include <iostream>
#include <functional>
enum Dir { H, V };
template<Dir d>
void call(double x, double y) {
std::function<double(double, double)> f;
if constexpr (d == H) {
f = [](double x, double y) -> double {
@rinfz
rinfz / ptr_crap.cc
Created March 6, 2019 22:06
Pointers and stuff
#include <iostream>
#include <memory>
#include <cstdlib>
#include <vector>
void incr(float *arr) {
arr[5] += 1;
arr[7] += 1;
}
[alias]
st = status
co = checkout
l = log
d = diff
db = !git diff -w origin/master...
ci = commit
br = !git --no-pager branch --sort=committerdate
ca = !git commit --amend --no-edit --date=now
uw = !git reset @~
@rinfz
rinfz / deref.nim
Created November 28, 2018 19:47
ada style ptr deref in nim with no overhead
template all[T](arg: ptr T): T = arg[]
var x = 10
echo x.addr.all
@rinfz
rinfz / main.p6
Created November 24, 2018 16:43
calling D from perl 6 (windows)
use NativeCall;
sub routine(int64) returns Str is native('mydll') { * }
my $start = now;
my $foo = routine(100_000);
say $foo;
say now - $start, " seconds";