Skip to content

Instantly share code, notes, and snippets.

@Dammmien
Dammmien / wget.sh
Last active March 13, 2024 13:58
wget cheat sheet
# POST a JSON file and redirect output to stdout
wget -q -O - --header="Content-Type:application/json" --post-file=foo.json http://127.0.0.1
# Download a complete website
wget -m -r -linf -k -p -q -E -e robots=off http://127.0.0.1
# But it may be sufficient
wget -mpk http://127.0.0.1
# Download all images of a website
@Dammmien
Dammmien / Matrix.js
Last active July 9, 2023 17:33
Easily create an empty matrix in javascript
var matrix = [],
H = 4, // 4 rows
W = 6; // of 6 cells
for ( var y = 0; y < H; y++ ) {
matrix[ y ] = [];
for ( var x = 0; x < W; x++ ) {
matrix[ y ][ x ] = "foo";
}
}
@Dammmien
Dammmien / mustache.md
Last active April 27, 2023 22:41
Mustache cheatsheet

Basic tag

  Hello {{name}} !!

Comments

 {{! This is a comment, and it won't be rendered }}
@Dammmien
Dammmien / dfs.js
Last active February 22, 2022 11:37
Depth First Search (DFS) Graph Traversal in Javascript
const nodes = [
{
links: [ 1 ], // node 0 is linked to node 1
visited: false
}, {
links: [ 0, 2 ], // node 1 is linked to node 0 and 2
visited: false
},
...
];
@Dammmien
Dammmien / bfs.js
Last active February 22, 2022 11:35
Breadth First Search (BFS) Graph Traversal in Javascript
var nodes = [
{
links: [ 1 ], // node 0 is linked to node 1
visited: false
}, {
links: [ 0, 2 ], // node 1 is linked to node 0 and 2
path: [],
visited: false
},
...
@Dammmien
Dammmien / average.js
Last active October 3, 2019 09:06
Average of an array ES6
var average = arr => arr.reduce( ( p, c ) => p + c, 0 ) / arr.length;
average( [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ] );
// 5
@Dammmien
Dammmien / index.js
Last active May 24, 2019 16:46
Minimalist static file server
#!/usr/bin/env node
const http = require('http');
const url = require('url');
const fs = require('fs');
const path = require('path');
const [ runtime, scriptName, port = 3000, folder = process.cwd() ] = process.argv;
class Server {
@Dammmien
Dammmien / Prototype.js
Created March 24, 2018 00:09
JavaScript Prototype design pattern
class Sheep {
constructor(name, weight) {
Object.assign(this, { name, weight });
}
clone() {
return new Sheep(this.name, this.weight);
}
@Dammmien
Dammmien / State.js
Created March 29, 2018 15:19
JavaScript State design pattern
class OrderStatus {
constructor(name, nextStatus) {
this.name = name;
this.nextStatus = nextStatus;
}
doSomething() {
console.log('Do nothing by default');
}
@Dammmien
Dammmien / Strategy.js
Created April 4, 2018 21:22
JavaScript Strategy design pattern
class ShoppingCart {
constructor(discount) {
this.discount = new discount();
this.amount = 0;
}
checkout() {
return this.discount.apply(this.amount);
}