Skip to content

Instantly share code, notes, and snippets.

@sillvva
sillvva / qsZod.ts
Created August 24, 2022 01:34
Query String Parser with Zod
import qs from "qs";
import { ZodSchema } from "zod";
const parseObjectPrimitives = (obj: Record<string, any>): any => {
return Object.fromEntries(
Object.entries(obj).map(([k, v]) => {
if (typeof v === "object") return [k, parseObjectPrimitives(v)];
if (!isNaN(parseFloat(v))) return [k, parseFloat(v)];
if (v === "true") return [k, true];
if (v === "false") return [k, false];
Taken from : https://www.smackfu.com/stuff/programming/shoutcast.html
Webarchive: https://web.archive.org/web/20190521203350/https://www.smackfu.com/stuff/programming/shoutcast.html
Shoutcast Metadata Protocol
How To Parse Titles from MP3 Streams
I wanted to add the ability to show titles from Shoutcast streams on the SliMP3, like Winamp does. The protocol isn't documented anywhere officially (of course). So I ended up cobbling together info from google caches, xmms source code, and mailing lists. Hopefully, this document will save others from the same fate.
## Step 0: Overview picture
-----------------------------------------------------------------------
[ audio data ][metadata.length][metadata][ audio data ]
@derindutz
derindutz / use-persistent-swr.ts
Last active January 6, 2023 08:11
useSWR with localforage as a persistent cache
import useSWR from '@zeit/swr';
import localForage from 'localforage';
import { ConfigInterface } from '@zeit/swr/dist/src/types';
import { useState, useEffect } from 'react';
export function usePersistentSWR(key: string, fn?: Function, config?: ConfigInterface) {
let handleSuccess;
if (config !== undefined && config.onSuccess !== undefined) {
const { onSuccess } = config;
handleSuccess = (data: any, key: string, config: ConfigInterface) => {
@cball
cball / Fastfile.rb
Last active April 13, 2024 21:04
Fastlane file for updating ids, display names, and icons w/ badges in React Native
# this should be the folder name under `ios` for your project
project_name = 'MyProject'
# NOTE: This is meant to be run on CI where it changes everything before building the app.
# Usage:
# `RN_RELEASE_TYPE=beta fastlane prep_release_type` (on CI these ENV variables should be set via the UI)
# Available release types: alpha, beta, production (default)
#
# If you're trying this script out locally, make sure you have ImageMagick installed, and discard the changes via git when you're done.
desc "Updates the app identifier, display name and icon for alpha, beta, and production releases"
@webframp
webframp / keybase.md
Created July 25, 2017 18:14
Signing git commits on github using keybase.io gpg key

Probably one of the easiest things you'll ever do with gpg

Install Keybase: https://keybase.io/download and Ensure the keybase cli is in your PATH

First get the public key

keybase pgp export | gpg --import

Next get the private key

@wikrie
wikrie / fritzbox-cert-update.sh
Last active July 15, 2024 14:47
Fritzbox Fritz!Box AVM SSL Letsencrypt automatically update
#!/bin/bash
## this little Gist is for Copy the Letsencrypt Cert from an Linux machine (e.g. Raspberry PI or Synology NAS)
## to the router (Fritzbox).
## It is usefull to be able to speak to the Router over DDNS without any Cert issue in the Browser.
## thanks to https://gist.github.com/mahowi for the perfect Idea
## put it in /etc/letsencrypt/renewal-hooks/post so it gets run after every renewal.
## since Fritz OS 7.25 it is needed to select a Username, from a security point of view
## it is always a good idea to have a non default user name. And as normaly a Fritz Box
## is connected to the Internet, the prefered method should be WITH Username.
@jsdario
jsdario / nuke-deps.sh
Last active December 12, 2023 08:36
Script to clean watchman, remove node_modules, clean cache and restart packager for React Native troubleshooting.
#!/bin/bash
# Stop cached listeners
watchman watch-del-all
# Remove installed modules
rm -rf node_modules
# Remove yarn meta files
rm yarn*
@joshduck
joshduck / gist:0c35f70cdd3abf88770c
Created February 24, 2016 21:58
ReactPerf to Web Tracing Framework
const ReactPerf = require('ReactPerf');
const TRACE_DOM = false;
function reactPerfTrace(objName: string, fnName: string, func: any): any {
return function(component) {
let label;
if (objName === 'ReactCompositeComponent') {
var instName = this.getName() || 'Unknown';
label = fnName === 'mountComponent' || fnName === 'updateComponent' ? instName : `${instName}.${fnName}`;
@mxstbr
mxstbr / idea.md
Last active February 16, 2021 18:33
Code splitting react-router routes with webpack 2

NOTE: Sokra confirmed I had a misunderstanding, Webpack is still a static build tool and the below won't work. It's still a nice concept though...

With webpack 1, code splitting react-router routes is quite tedious. It requires us to repeat the getComponent function over and over again. (See here for an explanation how it works with webpack 1)

Example:

<Router history={history}>
  <Route
    path="/"
@gaearon
gaearon / reducers.js
Last active December 11, 2020 14:56
How I'd do code splitting in Redux (pseudo code, not tested!)
import { combineReducers } from 'redux';
import users from './reducers/users';
import posts from './reducers/posts';
export default function createReducer(asyncReducers) {
return combineReducers({
users,
posts,
...asyncReducers
});