Skip to content

Instantly share code, notes, and snippets.

View jpillora's full-sized avatar
👶

Jaime Pillora jpillora

👶
View GitHub Profile
@jpillora
jpillora / _README.md
Created October 11, 2018 14:26
Export 28degress master card transactions to CSV

export-28deg.js

Export 28degress master card transactions to CSV

  1. Visit 28 degress transactions page
  2. Open Developer Console
  3. Paste code
  4. Press enter
@jpillora
jpillora / http-btn.js
Created March 12, 2019 14:52
Random Vue Stuff
import defaults from "lodash.defaults";
let httpBtn = {
bind: (el, binding) => {
//get options (evald expression)
let opts = binding.value;
if (typeof opts === "function") {
opts = {fn: opts};
}
//provide defaults
@jpillora
jpillora / scale.js
Last active October 7, 2019 11:40
Scale
//scale returns the number scaled to its corresponding SI suffix.
// scale(1234) => "1.2 K"
//MIT License, Copyright jpillora © 2019
function scale(n, d) {
// set default number
if (typeof n !== "number" || isNaN(n)) n = 0;
if (n === 0) return "0";
// set default digit count
if (typeof d !== "number" || isNaN(d)) d = 1;
// find scale index 1000,100000,... becomes 1,2,...
@jpillora
jpillora / icloud-dl.sh
Created February 7, 2021 06:47
Download iCloud link from Terminal
#!/bin/bash
# given "https://www.icloud.com/iclouddrive/<ID>#<Filename>
ID="...."
URL=$(curl 'https://ckdatabasews.icloud.com/database/1/com.apple.cloudkit/production/public/records/resolve' \
--data-raw '{"shortGUIDs":[{"value":"$ID"}]}' --compressed \
jq -r '.results[0].rootRecord.fields.fileContent.value.downloadURL')
curl "$URL" -o myfile.ext
@jpillora
jpillora / useAsync.ts
Created January 6, 2022 05:55
useAsync.ts
import { useCallback, useEffect, useState } from 'react'
// borrowed from https://usehooks.com/useAsync/
export function useAsync<T>(asyncFunction: () => Promise<T>, immediate = true) {
const [loading, setLoading] = useState(true)
const [value, setValue] = useState<T | null>(null)
const [error, setError] = useState<any>(null)
// The execute function wraps asyncFunction and
// handles setting state for pending, value, and error.
// useCallback ensures the below useEffect is not called
@jpillora
jpillora / README.md
Created November 1, 2022 12:14
kardianos/service MacOS example

Usage on MacOS

go build -o myservice

# installs and starts
./myservice

# plist file should be created
ls ~/Library/LaunchAgents/
func typeCache[T any](compute func(t reflect.Type) T) func(t reflect.Type) T {
cache := map[reflect.Type]T{}
return func(t reflect.Type) T {
if v, ok := cache[t]; ok {
return v
}
v := compute(t) // but compute cant recurse
cache[t] = v
return v
}
@jpillora
jpillora / README.md
Last active February 5, 2023 23:27
Vite + TypeScript + Reveal.js
  1. Setup

    npx create-vite
    # vanilla
    # typescript
    # enter name
    cd name/
    npm install reveal.js
@jpillora
jpillora / README.md
Last active February 6, 2023 01:01
Mininet demo on M1 Macs
@jpillora
jpillora / README.md
Created February 27, 2023 01:13
tailscale from source
go install -v tailscale.com/cmd/tailscale{,d}@latest

sudo tailscaled install-system-daemon

tailscale up

# login, approve

tailscale status