Skip to content

Instantly share code, notes, and snippets.

Brian Haak avesus

Block or report user

Report or block avesus

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View fold.txt
https://en.wikipedia.org/wiki/Fold_(higher-order_function)#Folds_as_structural_transformations
View the-best-string-ever.cpp
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 / lz77.cpp
Last active Aug 10, 2018
"Vanilla" LZ77
View lz77.cpp
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
unsigned int countBits(unsigned int number)
{
return (int)log2(number) + 1;
}
@avesus
avesus / wasm-compile.sh
Last active May 18, 2018
Complete WASM compilation
View wasm-compile.sh
~/wasmllvm/bin/clang++ -emit-llvm -fno-builtin -fshort-wchar --compile --sysroot=/root/wasmsysroot/ --target=wasm32-unknown-unknown-wasm client/main.cpp --optimize=3 -o client/app.bc && ~/wasmllvm/bin/llc -mtriple=wasm32-unknown-unknown-elf -filetype=asm -asm-verbose=false -o client/app.s client/app.bc && ~/binaryen/s2wasm client/app.s > client/app.wat && ~/wabt/wat2wasm client/app.wat -o client/app.wasm
View stylus-detection-methods.js
// Apple:
var body = document.getElementByTagName('body')
body.addEventListener('touchstart', function(evt){
// should be either "stylus" or "direct"
console.log(evt.touches[0].touchType)
})
// Chrome & Edge:
if (window.PointerEvent) {
// Pointer events are supported.
@avesus
avesus / bashrc
Created Dec 12, 2017
SpectrWM XTerm Background Color Change on Focus
View bashrc
finish() {
rm ${HOME}/.xterm-bash/$PPID
}
trap finish EXIT
echo -en $$ > ${HOME}/.xterm-bash/$PPID
@avesus
avesus / nginx.conf
Last active Dec 1, 2017
Nginx perfect nodern SPA config
View nginx.conf
location /app/ {
expires max;
}
location /img/ {
expires max;
}
location = /favicon.ico {
try_files $uri =204;
@avesus
avesus / September 2017 iOS WebKit input focus position: fixed.md
Created Sep 4, 2017
September 2017 iOS WebKit input focus position: fixed
View September 2017 iOS WebKit input focus position: fixed.md

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 / ios-fixed-keyboard.html
Created Sep 4, 2017
iOS keep fixed as fixed on input focus when virtual keyboard shows up and WebKit insanely scrolls the whole window
View ios-fixed-keyboard.html
<!DOCTYPE html>
<html style="height: 100%">
<head>
<meta name="viewport" content="initial-scale=1, minimum-scale=1, maximum-scale=1" />
<style>
#fixedsContainer {
position: absolute;
top: 0px;
bottom: 0px;
width: 320px;
@avesus
avesus / .bashrc
Last active Oct 18, 2019
Vim with NERDTree Adequate Defaults
View .bashrc
# 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
You can’t perform that action at this time.