Skip to content

Instantly share code, notes, and snippets.

View avesus's full-sized avatar
🎯
Focusing

Brian Cannard avesus

🎯
Focusing
View GitHub Profile
@avesus
avesus / icestick.pcf
Last active November 2, 2023 05:39
Lattice iCEstick + ILI9225 display
# full iCEstick pinout:
# http://www.pighixxx.com/test/portfolio-items/icestick/
set_io CLK_pad 21
set_io FT2232H_GPIOL2_pad 1
set_io FT2232H_GPIOL1_pad 2
set_io FT2232H_GPIOL0_pad 3
set_io FT2232H_TMS_CS_pad 4
set_io FT2232H_TDO_DI_pad 7
@avesus
avesus / arty.xdc
Last active November 2, 2023 05:39
Ethernet PHY and iCE40LP384 reprogrammer over UDP
#set_property DONT_TOUCH true [get_cells { evt1/mem1/srlatch_with_ands }]
#set_property DONT_TOUCH true [get_cells { evt1/pulse1/not1 }]
#set_property DONT_TOUCH true [get_cells { evt1/pulse1/xnor1 }]
#set_property DONT_TOUCH true [get_cells { evt1 }]
set_property SEVERITY {Warning} [get_drc_checks LUTLP-1]
#set_property ALLOW_COMBINATORIAL_LOOPS TRUE [get_nets evt1/feedback]
#set_property ALLOW_COMBINATORIAL_LOOPS TRUE [get_nets evt1/mem1/in0]
#set_property ALLOW_COMBINATORIAL_LOOPS TRUE [get_nets s1/evt1/mem1/OUTPUT_EDGE]
@avesus
avesus / common.glsl
Last active October 29, 2023 02:54
Cartilage Shader
# ifdef GL_FRAGMENT_PRECISION_HIGH
precision highp float;
precision highp int;
precision highp sampler2D;
# else
precision mediump float;
precision lowp int;
precision lowp sampler2D;
# endif
@avesus
avesus / ROMA.md
Created March 13, 2020 16:25
IO classification over Read, Overwrite, Move, Append

All external world facilities should have wrappers to support unit-testable and simply clean code.

These external world facilities:

a) might return different data when reads are requested because the data can be changed either by external "actors" or by a concurrent thread of the same client (this lambda); Examples: SQL SELECT, HTTP GET

b) do provide write APIs. We classify writes according if they destroy old data or make it unavailable at old locations

@avesus
avesus / the-best-string-ever.cpp
Created January 18, 2019 21:52
The Best String Ever
class TuffString {
public:
template <typename T, size_t Size>
TuffString (const T (&ptr) [Size]) : ptr(ptr), len(Size - 1) {
// _dev_logA("Pre-computed length\n");
}
TuffString (const void* pString) : ptr((const char*)pString) {
@avesus
avesus / gist:394fea04b34471fdf23d
Last active October 28, 2023 23:24
Unix style
program > file # write program stdout to file
program1 | program2 # send stdout of program1 to stdin of program2
program < file # write file to program stdin
program1 && program2 # exec program2 only if program1 returns 0
program1; program2 # exec program2 ever if program1 failed
cmd1; cmd2; cmd3 & - will only execute cmd3 in the background
cmd1 && cmd2 && cmd3 & - will execute the entire chain in the background IF there are no errors.
To cater for unconditional execution, using parenthesis solves this :
@avesus
avesus / test.c
Created April 21, 2015 22:30
iOS Multipath BSD Sockets Test. Comments welcomed!
# include <sys/types.h>
# include <sys/socket.h>
# include <ifaddrs.h>
# include <arpa/inet.h>
# include <netinet/in.h>
// Bad dirty quick functions written by hot fingers:
char* ipToStr(sockaddr* addr) {
static char ip[32];
@avesus
avesus / levmarq.c
Created July 10, 2023 16:33 — forked from maasencioh/levmarq.c
A simple implementation of the Levenberg-Marquardt algorithm in plain C
/*
* levmarq.c
*
* This file contains an implementation of the Levenberg-Marquardt algorithm
* for solving least-squares problems, together with some supporting routines
* for Cholesky decomposition and inversion. No attempt has been made at
* optimization. In particular, memory use in the matrix routines could be
* cut in half with a little effort (and some loss of clarity).
*
* It is assumed that the compiler supports variable-length arrays as
@avesus
avesus / September 2017 iOS WebKit input focus position: fixed.md
Created September 4, 2017 23:24
September 2017 iOS WebKit input focus position: fixed

Mobile Safari does not support position: fixed when an input focused and virtual keyboard displayed.

To force it work the same way as Mobile Chrome, you have to use position: absolute, height: 100% for the whole page or a container for your pseudo-fixed elements, intercept scroll, touchend, focus, and blur events.

The trick is to put the tapped input control to the bottom of screen before it activates focus. In that case iOS Safari always scrolls viewport predictably and window.innerHeight becomes exactly visible height.

Open https://avesus.github.io/docs/ios-keep-fixed-on-input-focus.html in Mobile Safari to see how it works.

Please avoid forms where you have several focusable elements because more tricks to fix position will be necessary, those were added just for demonstration purposes.

@avesus
avesus / .bashrc
Last active June 19, 2022 04:09
Vim with NERDTree Adequate Defaults
# I love super fast keyboard. Most of my friends and colleagues can't follow
# I use `atkbd.softrepeat=1` on the kernel command line.
# Even Visual Assist plugin in Visual Studio doubles keyboard repeat rate with _a reason_.
# I'm working on my laptop without X installed to avoid procrastination.
# I've spend a working day googling how to make `kbdrate` using slower delay than 250.
# Add this to your /etc/profile.d/kbdrate.sh: sudo kbdrate -r 82 -d 150 if you want it in console.
# Note that it will force you type password twice. I didn't find any workarounds.
xset r rate 150 82
# When exiting from Vim, just type