Skip to content

Instantly share code, notes, and snippets.

View alfonmga's full-sized avatar
👁️
What you look for is what you find.

Alfon alfonmga

👁️
What you look for is what you find.
View GitHub Profile
// Hop-by-hop headers. These are removed when sent to the backend.
// http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html
var hopHeaders = []string{
"Connection",
"Keep-Alive",
"Proxy-Authenticate",
"Proxy-Authorization",
"Te", // canonicalized version of "TE"
"Trailers",
"Transfer-Encoding",
-----BEGIN PGP MESSAGE-----
hQIMAwAAAAAAAAAAAQ//RDJG8JGUO/wEd+3RKru/2s2n/9fU2nA84Z8OxZHZr/t1
CToq95ZHRhM4m2wfi4BK0rdbZZy8/1tzRIkd6ISGJhFeYN1XlyCsEx/RDtoErieo
hF9F987xBbCHZexFRVN/MxgdPLEkYy1Jb9AARqz2isRYvU6yAhJI+HtdJsyxtIj/
A6klq4A5DMlUjt6t2wIUN8O1HlGIXeC68Ms4CAjFlyvvoj2AvAHAi0di11NLkh0z
MxG/EGfbfrP2F0miOMXNI40z0DzoY7aXI+PYtR0aqRJoZl14MdqBKoTickclZJ+m
QGJaz+ei9UzU/+ldyp8hUFCaGtcduXKOWp7hjA/kTrWD2puTJBytfrJ7RmXH5jX0
3n5Vd4zOe84CyRAwu8r3Fv/XAzDUewj/p/G7OEGKHG+wxoE4jx7jZ/PwuOgI8xPB
JhhBIBlS3lXoEdH5xS7SJnp82ekB1Dmes8TldfUMrvxLTCAJ22oK4cZW3YBEZb3o
@alfonmga
alfonmga / binary-tree-lexically-ordered.rs
Created July 6, 2021 16:24
Rust: binary tree lexically ordered
fn insert(&mut self, data: &str) {
if data < &self.payload {
match self.left {
Some(ref mut n) => n.insert(data),
None => self.set_left(Self::new(data)),
}
} else {
match self.right {
Some(ref mut n) => n.insert(data),
None => self.set_right(Self::new(data)),
@alfonmga
alfonmga / float-iterator.rs
Created July 6, 2021 16:02
Rust: Iterator over floating-point range
struct FRange {
val: f64,
end: f64,
incr: f64
}
fn range(x1: f64, x2: f64, skip: f64) -> FRange {
FRange {val: x1, end: x2, incr: skip}
}
@alfonmga
alfonmga / workflow-install.py
Created April 13, 2021 00:20 — forked from deanishe/workflow-install.py
Script to install/symlink Alfred workflows. Useful for workflow developers.
#!/usr/bin/python
# encoding: utf-8
#
# Copyright (c) 2013 <deanishe@deanishe.net>.
#
# MIT Licence. See http://opensource.org/licenses/MIT
#
# Created on 2013-11-01
#
@alfonmga
alfonmga / src.c
Created February 12, 2021 11:37
Check if given process PID has been executed from memory (memfd_create)
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
/*
* Checks if it's our target process
*/
static int is_our_target_process(int pid)
{
const { format } = require("date-fns");
/**
* logger is a small tool to centralize the logging of the application
* [@params](/params) {String} src - this will be prefixed before each message. It can be any string
* that would be significant when you read them in the logs (often in this code base it's the name
* of the file from where the log is sent)
*/
const logger = (src) => {
return {
@alfonmga
alfonmga / Checkbox.tsx
Last active June 13, 2022 16:06
React Final Form + Chakra UI
import {
Checkbox,
FormControl,
FormControlProps,
FormErrorMessage,
// FormLabel,
InputProps,
} from "@chakra-ui/core"
import React, { PropsWithoutRef } from "react"
import { useField } from "react-final-form"
@alfonmga
alfonmga / LazyLoadCSS.tsx
Created October 18, 2020 18:14
Next.js lazy load / preload CSS
import NextHead from 'next/head'
import { useEffect, useRef, useState } from 'react'
export type LazyLoadCSSProps = {
href: string
}
let hydrated = false
const LazyLoadCSS: React.FC<LazyLoadCSSProps> = ({ href }) => {
@alfonmga
alfonmga / Image.tsx
Created October 17, 2020 14:54
DatoCMS Image component
import React, { useCallback, useState } from "react";
import "intersection-observer";
import { useInView } from "react-intersection-observer";
const isSsr = typeof window === "undefined";
const universalBtoa = isSsr ? (str: string) => Buffer.from(str.toString(), 'binary').toString('base64') : window.btoa;
const isIntersectionObserverAvailable = isSsr
? false
: !!(window as any).IntersectionObserver;