Skip to content

Instantly share code, notes, and snippets.

View ianldgs's full-sized avatar
💻
Hacking

Ian Luca ianldgs

💻
Hacking
View GitHub Profile
import type { GetServerSideProps, GetServerSidePropsContext } from 'next';
/**
* Do not SSR the page when navigating.
* Has to be added right before the final getServerSideProps function
*
* On NextJS, navigation will trigger SSR, but it doesn't
* have any good way of giving feedback to the user that
* something is happening (loading).
* Also, traditional SSR only happens on first page visit.
/**
* Type used to declare a type-safe reducer without switch-cases.
*
* @example
* ```ts
* interface State {
* loading: boolean;
* }
*
* type Action = Readonly<
ls | while read file; do convert $file -resize 15% $(echo $file | sed -e 's/\.jpg/_thumb\.jpg/g'); done
@ianldgs
ianldgs / users.js
Last active February 24, 2020 14:29
NodeJS routing experiment
export default function UserRoutes({ db, jwt }) {
const Validation = ctx => ({
name: [required(), minLength(2), maxLength(255)],
email: [required(!ctx.body.phone), email(), uniqueUserEmail(db)],
phone: [required(!ctx.body.email), phone(), uniqueUserPhone(db)],
document: [
required(),
async doc => doc.match(/\d+/) || ValidationErrors.invalid_document
]
});
@ianldgs
ianldgs / dayjs-zoned.d.ts
Last active October 6, 2022 09:21
DayJS Zoned
import { Dayjs, PluginFunc, ConfigType } from 'dayjs';
declare const plugin: PluginFunc;
export = plugin;
declare module 'dayjs' {
/** Similar to date-fns/utcToZonedTime */
function utcToZoned(config: ConfigType, timezone?: string): Dayjs;
/** Similar to date-fns/zonedTimeToUtc */
@ianldgs
ianldgs / DebugAndoirdWebAppRemote.md
Last active October 4, 2019 14:09 — forked from KDawg/DebugAndoirdWebAppRemote.md
Debug Android WebApp Over Remote Chrome from OSX

Remote debugging USB-connected Android via Chrome

Phone Setup

  • Enable developer mode (depends on which android version or ui of the phone)
  • settings > developer options > usb debug enable
  • chrome > settings > developer tools > usb debug enable

Desktop Setup

/**
* @link https://jsperf.com/javascript-string-character-finder/7
*/
function indexesOf(string, regex) {
var match,
indexes = {};
regex = new RegExp(regex);
while (match = regex.exec(string)) {
const toSinglePromise = (acc, curr, o, arr) => arr = Promise.all(arr);
const toSinglePromise = (acc, curr, o, arr) => {
console.log('called', i+1, 'times')
return arr = Promise.all(arr)
};
await [Promise.resolve('a'), Promise.resolve('b')].reduce(toSinglePromise)
pg_dump --create --username=postgres deedmob > /var/data/shared/db.sql
psql --username=postgres deedmob /var/data/shared/db.sql
@ianldgs
ianldgs / go-localhost-cert.sh
Created May 29, 2019 19:48
Create localhost certificate
go run $GOROOT/src/crypto/tls/generate_cert.go --host="localhost"