Deriving a new Array from an existing Array:
['■','●','▲'].slice(1, 3) ⟼ ['●','▲']
['■','●','■'].filter(x => x==='■') ⟼ ['■','■']
['▲','●'].map(x => x+x) ⟼ ['▲▲','●●']
['▲','●'].flatMap(x => [x,x]) ⟼ ['▲','▲','●','●']
import * as path from 'node:path'; | |
import * as fs from 'node:fs/promises'; | |
const nodeModules = path.resolve('node_modules'); | |
let moduleNames = await fs.readdir(nodeModules); | |
moduleNames = (await Promise.all( | |
moduleNames.map(async name => { | |
if (name.startsWith('.')) { | |
return []; |
#!/bin/bash | |
## (c) 2022 Micael Levi L. C. | |
## This script requires: | |
## - npm (https://nodejs.org) | |
## - jq (https://stedolan.github.io/jq) | |
file="${1:-./package.json}" | |
[ -r "$file" ] || { echo "The file $file is not readable" ; exit 1 ; } |
const puppeteer = require('puppeteer'); | |
(async () => { | |
const browser = await puppeteer.launch({ devtools: true }); | |
const page = await browser.newPage(); | |
// Grants permission for changing geolocation | |
const context = browser.defaultBrowserContext(); | |
await context.overridePermissions('https://www.google.com/', ['geolocation']); |
import * as app from '.'; | |
import * as api from '@nestjs/common'; | |
@api.Controller() | |
export class TestController { | |
@api.Get() | |
@app.ResponseValidator(app.TestDto) | |
get() { | |
return new app.TestDto(); | |
} |
Sometimes you don't need all of jQuery's modules. Officially, you can use their Grunt script to build a slimmed-down jQuery, but what if Webpack is more your thing? Enter this guide.
fabric.Canvas.prototype.historyInit = function () { | |
this.historyUndo = []; | |
this.historyNextState = this.historyNext(); | |
this.on({ | |
"object:added": this.historySaveAction, | |
"object:removed": this.historySaveAction, | |
"object:modified": this.historySaveAction | |
}) | |
} |
import { createConnection, getConnection, Entity, getRepository } from "typeorm"; | |
import { PrimaryGeneratedColumn, Column } from "typeorm"; | |
@Entity() | |
export class MyEntity { | |
@PrimaryGeneratedColumn() | |
id?: number; | |
@Column() | |
name?: string; |
# ############################### # | |
# A/B TESTING (START) # | |
# ############################### # | |
# (1) Check if our cookie is already set. | |
# If so, redirect to the previously-viewed page. | |
RewriteCond %{HTTP_COOKIE} ab_test_vers=([^;]+) | |
RewriteRule ^THE-PAGE-BEING-TESTED$ HTTP://YOUR-DOMAIN.COM/tracking/%1 [cookie=ab_test_vers_match:true:YOUR-DOMAIN.COM,L] |