Skip to content

Instantly share code, notes, and snippets.

@ctrlplusb
ctrlplusb / findManyCursor.test.ts
Last active February 18, 2022 17:22
Utility to provide Relay Cursor Connection Specification support to Prisma Framework
import { Country, Photon } from '@prisma/photon';
import { findManyCursor } from './findManyCursor';
const photon = new Photon();
let data: Country[];
const createCountry = async (id: string) => photon.countries.create({
data: {
id,
@dohomi
dohomi / component.vue
Last active February 23, 2021 10:16
combine Nuxt asyncData with vue-apollo and watchQuery for client search
<script>
import allTravelsGql from '../../GQL/travel/allTravels.gql'
import {pagination, getSkipFirst} from '../../../generated-cms/util/pagination'
import {getTravelQuery, setCategoryOnQuery} from '../../util/getTravelQuery'
const buildQuery = variables => {
return {
query: allTravelsGql,
variables,
manual: true,
@joepie91
joepie91 / random.md
Last active November 7, 2024 16:48
Secure random values (in Node.js)

Not all random values are created equal - for security-related code, you need a specific kind of random value.

A summary of this article, if you don't want to read the entire thing:

  • Don't use Math.random(). There are extremely few cases where Math.random() is the right answer. Don't use it, unless you've read this entire article, and determined that it's necessary for your case.
  • Don't use crypto.getRandomBytes directly. While it's a CSPRNG, it's easy to bias the result when 'transforming' it, such that the output becomes more predictable.
  • If you want to generate random tokens or API keys: Use uuid, specifically the uuid.v4() method. Avoid node-uuid - it's not the same package, and doesn't produce reliably secure random values.
  • If you want to generate random numbers in a range: Use random-number-csprng.

You should seriously consider reading the entire article, though - it's