Skip to content

Instantly share code, notes, and snippets.

Avatar

Mikel MikelArnaiz

View GitHub Profile
View resume.json
{
"basics": {
"name": "John Doe",
"label": "Programmer",
"picture": "",
"email": "john@gmail.com",
"phone": "(912) 555-4321",
"website": "http://johndoe.com",
"summary": "A summary of John Doe...",
"location": {
@MikelArnaiz
MikelArnaiz / useColorScheme.ts
Last active Sep 23, 2020
Hook ColorScheme, is dark mode etc
View useColorScheme.ts
import { useState, useEffect } from 'react'
export enum ColorScheme {
Dark = 'dark',
Light = 'light',
NoPreference = 'no-preference',
}
export const useIsColorScheme = (colorScheme: ColorScheme) => {
const [isColorScheme, setIsColorScheme] = useState<boolean>(false)
@MikelArnaiz
MikelArnaiz / sort.ts
Created Sep 16, 2020
Sort compare function with key accessor
View sort.ts
type FilteredKeys<T, U> = { [P in keyof T]: T[P] extends U ? P : never }[keyof T]
const compare = <T>(fn: (x: T, y: T) => number) => <O extends object>(key: FilteredKeys<O, T>) => (
a: O,
b: O,
): number => {
const valA = (a[key] as unknown) as T
const valB = (b[key] as unknown) as T
return fn(valA, valB)
@MikelArnaiz
MikelArnaiz / sort.ts
Last active Sep 16, 2020
Sort compare curried function to access obj string properties values
View sort.ts
// https://stackoverflow.com/a/61476921/1355416
type FilteredKeys<T, U> = { [P in keyof T]: T[P] extends U ? P : never }[keyof T]
const compareStrings = <T extends object>(key: FilteredKeys<T, string>) => (a: T, b: T): number => {
const valA = (a[key] as unknown) as string
const valB = (b[key] as unknown) as string
return valA.localeCompare(valB)
}
View TimeZonesOffset.ts
// https://en.wikipedia.org/wiki/List_of_UTC_time_offsets
export enum TimeZoneOffset {
UTC_Minus_12_00 = '-12:00',
UTC_Minus_11_00 = '-11:00',
UTC_Minus_10_00 = '-10:00',
UTC_Minus_09_30 = '-09:30',
UTC_Minus_09_00 = '-09:00',
UTC_Minus_08_00 = '-08:00',
UTC_Minus_07_00 = '-07:00',
UTC_Minus_06_00 = '-06:00',
@MikelArnaiz
MikelArnaiz / getListOfType.ts
Last active Jun 5, 2020
Ensure getting an array with all items of a TypeScript type
View getListOfType.ts
/**
This util is a trick to ensure you get an array with all the elements of a type.
You have to pass an object with all the possible types as keys, and true as a value (arbitrarily chosen to be true)
*/
export const getListOfType = <A extends string>(obj: Record<A, true>): A[] => {
return keys(obj);
};
function keys<O extends object>(o: O): Array<keyof O> {
return Object.keys(o) as Array<keyof O>;
View Apostrophe vs Quotation Mark
Keys with Dutch keyboard
' Apostrophe: right key of semicolon
" Quotation Mark: right key of semicolon+shift
‘ Left Single Quotation Mark: alt+[
“ Left Double Quotation Mark: alt+]
’ Right Single Quotation Mark: alt+shift+[
” Right Double Quotation Mark: alt+shift+]
´ Acute Accent: alt+e
` Grave Accent: left key of z
@MikelArnaiz
MikelArnaiz / functions.php
Created Aug 11, 2017
How to add jQuery from CDN in Wordpress or how to disable jQuery
View functions.php
function disable_jQuery() {
if(!is_admin()){
wp_deregister_script('jquery');
}
}
function add_jQuery_from_cdn(){
if(!is_admin()){
wp_deregister_script('jquery');
wp_register_script('jquery', 'https://code.jquery.com/jquery-2.2.4.min.js', null, null, true);
@MikelArnaiz
MikelArnaiz / 010_increment_build_numbers.js
Last active Jun 26, 2017 — forked from ohh2ahh/increment_build_number.js
Cordova hook for incrementing build numbers. Increases only the platform you build
View 010_increment_build_numbers.js
#!/usr/bin/env node
// Fork of:
// https://gist.github.com/ohh2ahh/f35ff6e0d9f8b4268cdb
// Save hook under `project-root/hooks/before_build/`
//
// Don't forget to install xml2js using npm
// `$ npm install xml2js`
View gist:713b81ffdbb68ff836833760bbcf0a06
require('crypto').randomBytes(64).toString('hex');
You can’t perform that action at this time.