Skip to content

Instantly share code, notes, and snippets.

View dani-z's full-sized avatar
:octocat:

Daniel Zaremba dani-z

:octocat:
View GitHub Profile
@dani-z
dani-z / LocalStorage.js
Created January 18, 2018 19:17 — forked from danrigsby/LocalStorage.js
React Native Local Storage Wrapper
import React from 'react-native';
var {
AsyncStorage
} = React;
var LocalStorage = {
get: function (key) {
return AsyncStorage.getItem(key).then(function(value) {
return JSON.parse(value);
});
@dani-z
dani-z / package.json
Created February 23, 2018 15:14 — forked from drcmda/package.json
webpack 4
"scripts": {
"dev": "node .dev/webpack.dev.server.js",
"dev-prod": "node .dev/webpack.dev.server.js --production",
"build": "rimraf ./dist && webpack --config .dev/webpack.config.production.js --colors",
},
"devDependencies": {
"@babel/core": "7.0.0-beta.38",
"@babel/plugin-proposal-class-properties": "7.0.0-beta.38",
"@babel/plugin-proposal-decorators": "7.0.0-beta.38",
"@babel/plugin-transform-classes": "7.0.0-beta.38",
@dani-z
dani-z / most-popular-posts.ts
Created October 28, 2021 12:49 — forked from kentcdodds/most-popular-posts.ts
Prisma is awesome. I love this!
@dani-z
dani-z / encryption-example.js
Created February 27, 2022 09:51 — forked from perry-mitchell/encryption-example.js
Encryption and decryption using AES CBC in NodeJS, with key derivation
const { pbkdf2: deriveKey } = require("pbkdf2");
const crypto = require("crypto");
const DERIVATION_ROUNDS = 200000;
const HMAC_KEY_SIZE = 32;
const PASSWORD_KEY_SIZE = 32;
function pbkdf2(password, salt, rounds, bits) {
return new Promise((resolve, reject) => {
deriveKey(password, salt, rounds, bits / 8, "sha256", (err, key) => {
@dani-z
dani-z / createCtx-noNullCheck.tsx
Created December 29, 2022 22:56 — forked from swyxio/createCtx-noNullCheck.tsx
better createContext APIs with setters, and no default values, in Typescript. this is documented in https://github.com/typescript-cheatsheets/react-typescript-cheatsheet/blob/master/README.md#context
// create context with no upfront defaultValue
// without having to do undefined check all the time
function createCtx<A>() {
const ctx = React.createContext<A | undefined>(undefined)
function useCtx() {
const c = React.useContext(ctx)
if (!c) throw new Error("useCtx must be inside a Provider with a value")
return c
}
return [useCtx, ctx.Provider] as const