Follow these steps to add Ray globally available in your JavaScript/TypeScript project:
- Create the required files
$ mkdir ./ray
$ touch ./ray/index.js
$ touch ./ray/ray.d.ts
- Import in your app's entry
import 'path/to/ray';
import { useState } from 'react'; | |
import OpenAI from 'openai'; | |
import { Messages } from '@/types/Chat'; | |
const openai = new OpenAI({ | |
apiKey: process.env.NEXT_PUBLIC_OPENAI_API_KEY, | |
dangerouslyAllowBrowser: true, | |
}); |
{ | |
"people": [ | |
{"id":1,"firstname":"Amitie","lastname":"Dorking"}, | |
{"id":2,"firstname":"Lurlene","lastname":"Benyan"}, | |
{"id":3,"firstname":"Carrissa","lastname":"Hawkin"}, | |
{"id":4,"firstname":"Dukey","lastname":"Nolleau"}, | |
{"id":5,"firstname":"Benjy","lastname":"Durston"}, | |
{"id":6,"firstname":"Merrill","lastname":"MacAlpyne"}, | |
{"id":7,"firstname":"Harlin","lastname":"Endrici"}, | |
{"id":8,"firstname":"Reid","lastname":"Greve"}, |
#!/usr/bin/env zx | |
/* Require: | |
* - ImageMagick (https://imagemagick.org/) | |
* - rename (for macOS https://formulae.brew.sh/formula/rename) | |
* - zx (https://github.com/google/zx) | |
* | |
* Execute this script in your images source folder | |
* f.ex. $ cd my-original-images/ && npx zx generate-images.mjs | |
* |
// Dans Wordpress | |
// [16, 32, 48, 64, 96, 128, 256, 384, 640, 750, 828, 1080, 1200, 1920, 2048, 2880, 3840].forEach(width => { | |
// ratios.forEach(ratio => { | |
// add_image_size(`${ratio}-cool`, width, ratio.h * width / ratio.w ); | |
// }); | |
// }); | |
import useDimensions from "react-cool-dimensions"; | |
const loader = ({ src, width }) => { |
const delay = (time) => new Promise(resolve => setTimeout(resolve, time)); | |
const thanks = async () => { | |
console.log('👊'); | |
await delay(500); | |
console.log('🖐️'); | |
await delay(500); | |
console.log('🎤'); | |
}; |
class Calculator { | |
constructor(origin) { | |
this.origin = origin; | |
} | |
sum(...args) { | |
return args.reduce((acc, n) => typeof n === 'number' ? acc + n : acc, this.origin); | |
} | |
} |
const calculator = { | |
sum(...args) { | |
return args.reduce((acc, n) => typeof n === 'number' ? acc + n : acc, 0); | |
}, | |
sumOldSchool: function () { | |
return [...arguments].reduce(function (acc, n) { | |
if (typeof n === 'number') return acc + n; | |
return acc; | |
}, 0); |
const sum = { | |
current: 0, | |
get result() { | |
return `The current result is ${this.current}`; | |
}, | |
set add(n) { | |
if (typeof n === 'number') this.current = this.current + n; | |
} | |
}; |
const sum = (...args) => { | |
return args.reduce((acc, n) => typeof n === 'number' ? acc + n : acc, 0); | |
} | |
sum(31,7,4); // return 42 |