Skip to content

Instantly share code, notes, and snippets.

View goldingdamien's full-sized avatar

Damien Golding goldingdamien

View GitHub Profile
@cometkim
cometkim / index.mjs
Created March 25, 2022 16:55
Search all packages that doesn't support ESM from node_modules directory
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 [];
@micalevisk
micalevisk / show_last_modified_dates.sh
Last active July 23, 2023 23:12
Display the last modified date of every package on package.json dependencies list using npm-view (https://docs.npmjs.com/cli/v7/commands/npm-view)
#!/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 ; }

Cheat sheet: JavaScript Array methods

Deriving a new Array from an existing Array:

['■','●','▲'].slice(1, 3)           ['●','▲']
['■','●','■'].filter(x => x==='■')  ['■','■']
    ['▲','●'].map(x => x+x)         ['▲▲','●●']
    ['▲','●'].flatMap(x => [x,x])   ['▲','▲','●','●']
@ankitsadariya
ankitsadariya / geolocation.js
Created February 2, 2021 07:07
set geolocation for website using puppeteer
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']);
@Deathspike
Deathspike / Controller.ts
Last active March 28, 2023 08:06
nestjs response validation example (using express)
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();
}
@jjsquady
jjsquady / nextjs-deploy.md
Last active May 2, 2024 08:20
Deploying NEXTJS site with nginx + pm2

How to setup next.js app on nginx with letsencrypt

next.js, nginx, reverse-proxy, ssl

1. Install nginx and letsencrypt

$ sudo apt-get update
$ sudo apt-get install nginx letsencrypt

Also enable nginx in ufw

@rhaglennydd
rhaglennydd / README.md
Last active May 4, 2024 17:47
Custom jQuery Build for a Webpack Flow

Custom jQuery Build for a Webpack Flow

Why?

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.

The Steps

  1. From your project root, install jQuery as a dev dependency:
@alimozdemir
alimozdemir / fabric-history.js
Last active December 12, 2023 11:55
Fabricjs basic history implementation
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
})
}
@Ciantic
Ciantic / example-typeorm-jest.test.ts
Created April 16, 2019 17:50
Example of testing TypeOrm with Jest and Sqlite in-memory database
import { createConnection, getConnection, Entity, getRepository } from "typeorm";
import { PrimaryGeneratedColumn, Column } from "typeorm";
@Entity()
export class MyEntity {
@PrimaryGeneratedColumn()
id?: number;
@Column()
name?: string;
@iconifyit
iconifyit / htaccess-ab-test
Last active February 10, 2023 03:09
A/B Testing with htaccess
# ############################### #
# 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]