Skip to content

Instantly share code, notes, and snippets.

View psenger's full-sized avatar
:octocat:
Makin Bacon

Philip A Senger psenger

:octocat:
Makin Bacon
View GitHub Profile
@psenger
psenger / flatmap.js
Last active July 5, 2023 14:06
[An array of data, that has an array of sub data] #JavaScript #Array #flatMap #flat #reduce #reduceRIght
/**
* Problem: an array of data, that has an array of sub data.
* Three ways to do this:
* - map+split, reduce, push+spread, sort ( side effect: order is not retained )
* - map+split, flat
* - flatMap+split
*/
const values = 'a|b|c|d,e|f,g|h|i|j|k|l'
const A = values.split(',').map((v)=>v.split('|')).reduce((acc,v)=>{
@psenger
psenger / README.md
Last active July 3, 2023 03:26
[Apache HTTPD] #apache #unix

Apache Installation

yum install httpd -y

Default install directory /var/www/html

Apache Starting

@psenger
psenger / CURRY.md
Last active December 18, 2023 06:32
[Monad and Curry] #functionalProgramming

Curry

Currying is the process of turning a function that expects multiple parameters into one that, when supplied fewer parameters, returns a new function that awaits the remaining ones. [1]


[1] https://fr.umio.us/favoring-curry/

@psenger
psenger / greed-spy.js
Created June 9, 2023 07:46
[Greedy Spy on next value] #Array #JavaScript
const pattern = 'abcdefgh';
for (const [currentChar, nextChar] of pattern.split('').reduce((acc,value,idx,arr)=>{const entry = [value]; if ( arr.length > idx + 1 ) entry.push(arr[idx+1]); acc.push(entry); return acc},[])) {
console.log(currentChar,nextChar)
}
/**
a b
b c
c d
d e
@psenger
psenger / loadCSV.js
Last active June 6, 2023 08:33
[Best way to load CSV's without csv-parser] #JavaScript #CSV
const {readFile} = require("fs").promises;
const run = async () => {
const loadCSV = async (fileName ) => {
const contents = await readFile(fileName, 'utf8');
const lines = contents
.split('\n')
.filter(Boolean)
.map((t)=>t.trim()) // remove leading and trailing \r for non-utf8 files
.map((line)=>{
@psenger
psenger / README.md
Created June 2, 2023 02:59
[How to split a file based on line numbers] #Unix #MacOS

How to split a file on lines

Use case, you have a csv file, you want it to be split by 100 line numbers into files.. The onlys ide effect is you get sample-aa, sample-ab.... no extension

split -l 100 sample.csv sample-
@psenger
psenger / s3-aws.js
Created May 11, 2023 22:41
[S3 ES6 AWS] #AWS #S3
const AWS = require('aws-sdk')
const fs = require("fs").promises;
const {join} = require('path')
const path = require("path");
const { createReadStream, createHash } = require('crypto')
const credentials = {
accessKeyId: process.env.AWS_ACCESS_KEY_ID || 'test',
secretAccessKey: process.env.AWS_SECRET_KEY || 'test' ,
}
@psenger
psenger / readme.md
Created April 28, 2023 04:19
[How to determine the files that have changed in a git commit to a specific hashcode] #git

git diff --name-only HEAD

@psenger
psenger / readme.md
Created April 25, 2023 23:36
[process.exit] #NodeJS

In Node.js, the process.exit() method is used to exit the current Node.js process with a given exit code. The number argument passed to process.exit() represents the exit code that the Node.js process will exit with.

Here are the commonly used exit codes and their meanings:

  • 0: The process exits successfully without any errors.
  • 1: The process exits due to an uncaught exception.
  • 2: The process exits due to a misconfiguration or missing file.
  • 3: The process exits due to a fatal error.
@psenger
psenger / readme.md
Created April 25, 2023 09:19
[process.nextTick setImmediate] #NodeJS

Process NextTick and SetImmediate

In Node.js, process.nextTick() is a method that allows you to schedule a function to be executed on the next iteration of the event loop. It is often used to defer the execution of a function until after the current function has completed.

The process.nextTick() method is similar to setImmediate(), but with a few key differences. While setImmediate() schedules a callback to run in the next iteration of the event loop, process.nextTick() schedules a callback to run at the end of the current iteration of the event loop, before any I/O operations.

Here is an example of how process.nextTick() can be used:

console.log('start');