Skip to content

Instantly share code, notes, and snippets.

View shulhi's full-sized avatar
🏃‍♂️

Shulhi Sapli shulhi

🏃‍♂️
View GitHub Profile
@mizlan
mizlan / .zshrc
Last active January 13, 2023 13:02
Configuration for seamless transition between light and dark modes. See video https://youtu.be/TSSkUD7vY00.
# CHANGE THE COLORS TO THE RELEVANT ONES FOR YOUR COLORSCHEME
fzf() {
if grep -q dark "$HOME/theme"; then
FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --color=fg:#e0def4,bg:#2a273f,hl:#6e6a86 --color=fg+:#908caa,bg+:#232136,hl+:#908caa --color=info:#9ccfd8,prompt:#f6c177,pointer:#c4a7e7 --color=marker:#ea9a97,spinner:#eb6f92,header:#ea9a97" /opt/homebrew/bin/fzf
else
FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --color=fg:#575279,bg:#fffaf3,hl:#9893a5 --color=fg+:#797593,bg+:#faf4ed,hl+:#797593 --color=info:#56949f,prompt:#56949f,pointer:#907aa9 --color=marker:#d7827e,spinner:#b4637a,header:#d7827e" /opt/homebrew/bin/fzf
fi
}
@Eleven-am
Eleven-am / phœnix-channels-react-hook.tsx
Last active August 15, 2022 09:39
This is a relatively typed phoenix channels hook that works incredibly well with react. you can create the same channels in multiple components as they share the same channel singleton
import {
createContext,
ReactNode,
useCallback,
useContext,
useEffect, useMemo,
useRef,
useState
} from "react";
import {Channel, Presence, Socket} from "phoenix";
@alarbada
alarbada / GADTs.res
Created August 16, 2021 09:44
Rescript syntax for GADTs
// Sources
// https://stackoverflow.com/questions/58964775/pattern-matching-on-a-gadt-fails
// GADTs in rescript.
// GADTs are cool. Here's an example of a function with polymorphic return type.
// The thing is that the syntax is buried somewhere I don't remember, and the
// docs won't say anything because this is sort of black magic. Apply with care.
type rec prim<'t> =
@andywer
andywer / _readme.md
Last active March 7, 2024 05:52
React - Functional error boundaries

React - Functional error boundaries

Thanks to React hooks you have now happily turned all your classes into functional components.

Wait, all your components? Not quite. There is one thing that can still only be implemented using classes: Error boundaries.

There is just no functional equivalent for componentDidCatch and deriveStateFromError yet.

Proposed solution

@jswny
jswny / Flexible Dockerized Phoenix Deployments.md
Last active July 3, 2023 05:25
A guide to building and running zero-dependency Phoenix (Elixir) deployments with Docker. Works with Phoenix 1.2 and 1.3.

Prelude

I. Preface and Motivation

This guide was written because I don't particularly enjoy deploying Phoenix (or Elixir for that matter) applications. It's not easy. Primarily, I don't have a lot of money to spend on a nice, fancy VPS so compiling my Phoenix apps on my VPS often isn't an option. For that, we have Distillery releases. However, that requires me to either have a separate server for staging to use as a build server, or to keep a particular version of Erlang installed on my VPS, neither of which sound like great options to me and they all have the possibilities of version mismatches with ERTS. In addition to all this, theres a whole lot of configuration which needs to be done to setup a Phoenix app for deployment, and it's hard to remember.

For that reason, I wanted to use Docker so that all of my deployments would be automated and reproducable. In addition, Docker would allow me to have reproducable builds for my releases. I could build my releases on any machine that I wanted in a contai

/* file: Recompose.re */
/* The very definition of a HOC, it's a function that gets a react component and returns another react component */
type hoc = ReasonReact.reactClass => ReasonReact.reactClass;
module type CreateWithStateParams = {
/* This is the secret sauce ingredient, with it the users can pass whatever state they want */
type state;
let defaultValue: state;
};
@lilactown
lilactown / promises.re
Last active August 20, 2022 07:56
Notes on using JavaScript Promises in ReasonML/BuckleScript
/**
* Making promises
*/
let okPromise = Js.Promise.make((~resolve, ~reject as _) => [@bs] resolve("ok"));
/* Simpler promise creation for static values */
Js.Promise.resolve("easy");
Js.Promise.reject(Invalid_argument("too easy"));
<input v-el="avatar" type="file" name="avatar" id="avatar" v-on="change:upload">
methods: {
upload: function(e) {
e.preventDefault();
var files = this.$$.avatar.files;
var data = new FormData();
// for single file
data.append('avatar', files[0]);
// Or for multiple files you can also do
// _.each(files, function(v, k){

This document has moved!

It's now here, in The Programmer's Compendium. The content is the same as before, but being part of the compendium means that it's actively maintained.

@CMCDragonkai
CMCDragonkai / existential_types_haskell.md
Last active June 10, 2020 06:48
Existential Types in Haskell

Existential Types in Haskell

I had always been confused by Haskell's implementation of existential types. Until now!

Existential types is the algebraic data type (ADT) equivalent to OOP's data encapsulation. It's a way of hiding a type within a type. Hiding it in such a way that any consumer of the data type won't have any knowledge on the internal property