Skip to content

Instantly share code, notes, and snippets.

View juliencrn's full-sized avatar

Julien juliencrn

View GitHub Profile
@juliencrn
juliencrn / branded-type.ts
Created January 11, 2024 00:00
Branded type
// https://egghead.io/blog/using-branded-types-in-typescript
// In its own module (file) to keep `Brand` private
declare const __brand: unique symbol
type Brand<B> = { [__brand]: B }
export type Branded<T, B> = T & Brand<B>
@juliencrn
juliencrn / AdSenseBanner.tsx
Created September 30, 2022 20:11
Google AdSense banner React-Typescript component
import { useEffectOnce } from 'usehooks-ts'
declare global {
interface Window {
adsbygoogle: unknown[]
}
}
interface AdSenseProps {
slot: string
import React from 'react'
import { useTernaryDarkMode } from 'usehooks-ts'
export default function Component() {
const {
isDarkMode,
useSystemPrefers,
setTernaryMode,
toggleSystemPrefers,
// ES6 Generators
// @See: https://medium.com/dailyjs/a-simple-guide-to-understanding-javascript-es6-generators-d1c350551950
function* gChild() {
yield 2;
yield 3;
}
function* gMain() {
yield 1;
// Pipe in JS
// @see
// - https://www.freecodecamp.org/news/pipe-and-compose-in-javascript-5b04004ac937/
// - https://medium.com/javascript-scene/reduce-composing-software-fe22f0c39a1d
// Utility functions for example
const getName = (person) => person.name
const uppercase = (string) => string.toUpperCase()

Keybase proof

I hereby claim:

  • I am juliencrn on github.
  • I am juliencrn (https://keybase.io/juliencrn) on keybase.
  • I have a public key ASD2CEsmK_N5f6bcWRI9C4eEvXm2btLMzsXqtG57X7oEwAo

To claim this, I am signing this object:

@juliencrn
juliencrn / LAMP-based-docker.md
Last active August 21, 2019 13:21
Setup LAMP using Devilbox (Docker based)

Local PHP server based on Docker

Requirements

  • Docker
  • Docker-compose

Installation

Get the devilbox

git clone https://github.com/cytopia/devilbox

@juliencrn
juliencrn / gitignore.sh
Created May 30, 2019 13:37
Remove .idea files from PHPStorm with git & .gitignore
# Remove the file from the repository
git rm --cached .idea/
# now update your gitignore file to ignore this folder
echo '.idea' >> .gitignore
# add the .gitignore file
git add .gitignore
git commit -m "Removed .idea files"
@juliencrn
juliencrn / parse-url.js
Created May 25, 2019 23:41
Read URL using JS
// Assuming "?post=1234&action=edit"
const urlParams = new URLSearchParams(window.location.search);
console.log(urlParams.has('post')); // true
console.log(urlParams.get('action')); // "edit"
console.log(urlParams.getAll('action')); // ["edit"]
console.log(urlParams.toString()); // "?post=1234&action=edit"
console.log(urlParams.append('active', '1')); // "?post=1234&action=edit&active=1"
@juliencrn
juliencrn / gulp.sh
Created May 25, 2019 23:39
[Gulp] How to fix "Error: EACCES: permission denied, mkdir"
sudo npm install --unsafe-perm=true --allow-root