Skip to content

Instantly share code, notes, and snippets.

@menduz
menduz / attenuation.glsl
Created May 31, 2020
Cheap attenuation
View attenuation.glsl
float dist = length(lightVector);
float lightR = (lightPosRadius.w / uViewSize.y);
if(dist < lightR){
float attenuation = dist/(1.0 - (dist/lightR) * (dist/lightR));
attenuation = attenuation / lightR + 1.0;
attenuation = 1.0 / (attenuation * attenuation);
if (attenuation > 0.0) {
@menduz
menduz / sphere-normals.hlsl
Created May 30, 2020
Spherical normal encoding
View sphere-normals.hlsl
// Encoding:
normalOut=normalize(normalIn.xy)*sqrt(normalIn.z*0.5+0.5);
// Decoding:
normal.z=length2(normalOut.xy)*2- 1;
normal.xy=normalize(normalOut.xy)*sqrt(1- normal.z*normal.z);
@menduz
menduz / normals.hlsl
Last active May 30, 2020
Normal encoding/decoding in float2
View normals.hlsl
//Encoding:
float2 atanYX = atan2(normalIn.y,normalIn.x);
float2 normalOut = float2(atanYX/PI,normalIn.z);
normalOut = (normalOut+1.0)+0.5;
//Decoding:
float2 angles = normalOut*2.0- 1.0;
float2 theta = sincos(angles.x*PI,theta.x,theta.y);
float2 phi = float2(sqrt(1.0- angles.y*angles.y),angles.y);
float3 normal = float3(theta.y*phi.x,theta.x*phi.x,phi.y);
View colors.yaml
colors:
primary:
background: '0x333333'
foreground: '0xd3d0c8'
cursor:
text: '0x000000'
cursor: '0xffffff'
normal:
black: '0x000000'
red: '0xf2777a'
@menduz
menduz / mapUntil.dwl
Created Nov 5, 2019
mapUntil skipUntil in DataWeave
View mapUntil.dwl
%dw 2.0
output application/json
fun mapUntil<T, V>(
iterableList: Array<T>,
predicate: (element: T, index: Number) -> ({value: V} | {done: Boolean}),
startIndex: Number = 0
) =
iterableList match {
case [] -> []
View clojure.ebnf
{ws=explicit}
Document ::= WS* Forms EOF {ws=implicit}
Form ::= (&"(" List | &"[" Vector | &"{" Map| &"#{" Set| &"'" Quote| &"`" Backtick| &"@" Deref| &"~@" UnquoteSplicing| &"~" Unquote| &"#(" Lambda| !';' Symbol| &":" Keyword | Literal | Discard | Dispatch | Regex) {pin=1,fragment=true}
Forms ::= (Form WS* | Comment WS*)* {fragment=true}
List ::= OPEN_PAREN WS* Forms? WS* CLOSE_PAREN {pin=1,recoverUntil=CLOSE_PAREN}
Vector ::= OPEN_ARRAY WS* Forms? WS* CLOSE_ARRAY {pin=1,recoverUntil=CLOSE_ARRAY}
@menduz
menduz / NAT.ts
Created Jul 25, 2019
DetectNAT.ts
View NAT.ts
export enum NatType {
Other = 0,
SymmetricNAT = 1,
NoNAT = -1 // No NAT (Open Internet, Blocked, Symmetric UDP Firewall)
}
export async function detectNat(): Promise<NatType> {
const candidates = new Map<number, number[]>();
const pc = new RTCPeerConnection(peerConnectionConfig);
@menduz
menduz / webrtc.ts
Created Jul 14, 2019
WebRTC basic setup
View webrtc.ts
// This configuration is passed when we create a new peer connection object.
// It provides a set of servers used to establish a connection. STUN servers
// are used to discover our external IP address, and TURN servers (none listed
// here) are used to proxy a connection when a peer is behind a restrictive
// firewall that prevents a direct connection.
var peerConnectionConfig = {
iceServers: [
{ urls: "stun:stun.l.google.com:19302" },
{ urls: "stun:stun1.l.google.com:19302" },
{ urls: "stun:stun2.l.google.com:19302" },
@menduz
menduz / ao-ind-conversor.js
Created Jul 13, 2019
ao-ind-conversor.js
View ao-ind-conversor.js
const bb = require("./bytebuffer");
const fs = require("fs");
function loadBB(src) {
return bb.wrap(fs.readFileSync(src));
}
function loadCabecera(bb) {
bb.skip(255 + 4 + 4);
}
@menduz
menduz / yubikey-reset.sh
Created May 24, 2019 — forked from pkirkovsky/yubikey-reset.sh
Utility for resetting a Yubikey to factory defaults using gpg-connect-agent. This will wipe out any stored keys and reset PINs to default values.
View yubikey-reset.sh
gpg-connect-agent <<EOF
/hex
scd serialno
scd apdu 00 20 00 81 08 40 40 40 40 40 40 40 40
scd apdu 00 20 00 81 08 40 40 40 40 40 40 40 40
scd apdu 00 20 00 81 08 40 40 40 40 40 40 40 40
scd apdu 00 20 00 81 08 40 40 40 40 40 40 40 40
scd apdu 00 20 00 83 08 40 40 40 40 40 40 40 40
scd apdu 00 20 00 83 08 40 40 40 40 40 40 40 40
scd apdu 00 20 00 83 08 40 40 40 40 40 40 40 40
You can’t perform that action at this time.