cli

create bigfile in cli

create bigfile in cli:

tr -dc "A-Za-z 0-9" < /dev/urandom | fold -w100|head -n 1000000 > bigfile.txt
Tags: 

Bun

Node Js

  • Node team is klein team en onbetaald
  • Voortgang Node versies gaat vooral over niet te veel breaken met voorgaande versies
  • Hierdoor blijven kritisch perfomance issues liggen
  • Gebouwd op de V8 engine. Kijk bv naar de code van de shell

Bun

  • Het Bun team zet in op performance
  • Heeft links met React en Vue
  • Probeert het hele eco systeem van Node te kunnen draaien
  • Kort gezegd een snellere Node

Klachten over Node

  • single threaded & concurrency
  • callbacks
  • Loops
  • Limited standard Libs
  • CPU perfomant tasks & Memory consumption
  • debugging
  • gemopper over update cycle en deprecations

Bun Safari Engine

Safari engine voordelen:
- batterij
- performance webkit
- security
- CJS and ES6 and beyond support
- cross-platform
- kleiner en sneller
- voor de browser

Safari


Wat is Bun nou?

het staat op : Bun Home Page Op Youtube zeggen ze zelf: - Bun is still under development. - Use it to speed up your development workflows or run simpler production code in resource-constrained environments like serverless functions.

- We're working on more complete Node.js compatibility and integration with existing frameworks.

Wat Bun is nou

  • Bun is an all-in-one toolkit for JavaScript and TypeScript apps. It ships as a single executable called bun​.
  • At its core is the Bun runtime, a fast JavaScript runtime designed as a drop-in replacement for Node.js.
  • It's written in Zig and powered by JavaScriptCore under the hood, dramatically reducing startup times and memory usage.
  • Werkt (nog) niet op Windows

Bun Install

Op Linux achtige machines:

# with install script (recommended)  
curl -fsSL https://bun.sh/install | bash  

# with npm  
npm install -g bun  

# with Homebrew  
brew tap oven-sh/bun  
brew install bun  

# with Docker  
docker pull oven/bun  
docker run --rm --init --ulimit memlock=-1:-1 oven/bun  

bun init

Na de check of bun t doet:

bun --version  

Kan je:

bun init

Bun commands

Net zoals npm

upgrade

bun upgrade    

To install dependencies:

bun install
bun i

bun start inhoud folder

branche 01_init na

bun init

bevat de folder

.gitignore
README.md
bun.lockb
index.ts
node_modules
package.json
tsconfig.json


Bun run

hierna klaar voor:

bun run index.ts    

Bun imports

branche 02_say_hello

import van andere ts file


Bun serve

branch 03_bun_serve

start een server op zoals in bv express


Bun scripts

branch 04 bun run start

"scripts": {  
  "start": "bun run index.ts"  
},

Bun Scripts 2

{  
  // ... other fields  
  "scripts": {  
    "clean": "rm -rf dist && echo 'Done.'",  
    "dev": "bun server.ts"  
  }  
}  

bun run clean  
bun run dev  

Bun tsconfig

branch 5 dom en tsconfig

rare errors van mn lsp kon ik oplossen met:

/// <reference lib="dom" />  
/// <reference lib="dom.iterable" />

Bun run

bun run index.ts    

To run a file in watch mode, use the --watch flag.

bun --watch run index.tsx  

Scripts

{  
  // ... other fields  
  "scripts": {  
    "clean": "rm -rf dist && echo 'Done.'",  
    "dev": "bun server.ts"  
  }  
}  

bun run clean  
bun run dev  

Bun test

Bun pagina Run tests

bun test  

Tests are written in JavaScript or TypeScript with a Jest-like API. Refer to Writing tests for full documentation.


Bun test 2

The runner recursively searches the working directory for files that match the following patterns:

  • *.test.{js|jsx|ts|tsx}
    *_test.{js|jsx|ts|tsx}
  • *.spec.{js|jsx|ts|tsx}
  • *_spec.{js|jsx|ts|tsx}

You can filter the set of test files to run by passing additional positional arguments to bun test.


Test example

  • 06_test branche* math.test.ts
import { expect, test } from "bun:test";  

test("2 + 2", () => {  
  expect(2 + 2).toBe(4);  
});  

Elysia

Elisia De Express van / met Bun

bun create elysia app

Elysia 2

  • Performance : You shall not worry about the underlying performance
  • Simplicity : Simple building blocks to create an abstraction, not repeating yourself
  • Flexibility : You shall be able to customize most of the library to fits your need

eenvoudig integratie met swagger


Performance For Loops

branche 07 for loops

start de node versie

node forloop.js

start de bun versie

bun start

Performance server

express bun en elysia

met artillery

ontloopt elkaar niet heel veel

voordelen op openshift?

toon results


Project met Tailwind

toon crm project

voordeel alles wordt razend snel door bun gecompileerd

Bun runt project en de bundle

css wordt gegenereerd door Tailwind


Performance packages en cache

youtube en bun pagina vol met voorbeelden.


Toekomst

Node en Bun zullen voorlopig naast elkaar bestaan

Bun is nog niet productie klaar

Geen Windows versie


Bun en Angular

Installeer new project met ng new projectName daarna cd de map in en bun i
De eerste keer duurt dat even lang als npm i.
bun start om het project te starten. Duurt de eerste keer ook even lang als npm start. Als je nu
rm package-lock.json && rm -rf /node_modules
en daarna weer bun i && bun start dan gaat alles wel veel sneller (op mijn systeem bunnen 3s ).
Vooral handig als je snel je node_modules wil verwijderen en weer opnieuw wil installeeren zoals bv bij het upgraden van Angular.


Github

AWK

Awk operates on a per-line basis, where it reads input line by line, applies patterns and actions, and then produces output based on those patterns.

Extracts disk usage percentage for the root file system

df -h | awk '$NF == "/" {print "Usage:", $5}'

Lists processes using more than 10% CPU

ps aux | awk '{if ($3 >= 10) print $0}'

Monitors CPU and memory usage of a process by PID

top -p PID -n 1 | awk '/PID/{getline; print "CPU:", $9, "MEM:", $10}'

Monitors CPU and memory usage of a specific user

awk -F':' '{ print "User:", $1, "Home:", $6 }' /etc/passwd

Extracts lines containing "error" from syslog

awk '/error/ {print $0}' /var/log/syslog

Displays network interfaces and their IP addresses

ifconfig | awk '/inet addr/{print "Interface:", $1, "IP:", $2}'

Checks if a service is active or not

systemctl is-active service-name | awk '{print "Service Status:", $0}'

Shows system uptime

uptime | awk '{print "Uptime:", $3, $4}'

Displays total and used memory

free -m | awk '/Mem/{print "Total Memory:", $2 "MB", "Used Memory:", $3 "MB"}'

Lists open ports in listening state

netstat -tuln | awk '/LISTEN/{print "Port:", $4}'

Lists top 5 largest directories

du -h /path | sort -rh | awk 'NR<=5{print $2, $1}'

Displays CPU model information

awk -F: '/model name/ {print "CPU Model:", $2}' /proc/cpuinfo

Monitors disk I/O for a specific disk (e.g., sda)

iostat -x 1 | awk '$1=="sda" {print "Read:", $6 "KB/s, Write:", $7 "KB/s"}'

Lists active network connections and their states

ss -tuln | awk 'NR>1 {print "Protocol:", $1, "State:", $2, "Local Address:", $4}'

Displays system load averages

uptime | awk -F'[a-z]:' '{print "Load Average (1/5/15 min):", $2, $3, $4}'

Captures CPU and memory usage snapshot

top -b -n 1 | awk '/Cpu/{print "CPU Usage:", $2 "%"}; /KiB Mem/{print "Memory Usage:", $8}'
Tags: 

Brew

brew list

View Dep tree

for package in $(brew leaves); do echo $package; brew deps $package; echo; done 

Leaves

List top-level installed packages

brew leaves

with sizes:

brew list --formula | while read cask; do echo -n "$cask: "; du -sh $(brew --prefix)/Cellar/$cask; done

Update & Upgrade

brew update && brew upgrade 

Brew Info

brew info 
Tags: 

audio stereo to mono script

Convert all files as duo mono files

create a folder in which you want to convert the stereo clips to mono.

#!/bin/bash

for f in .wav; do ffmpeg -i "$f" \
-filter_complex "[0:a]channelsplit=channel_layout=stereo[L][R]" \
-map "[L]" "${f%.
}_EXTRACTED_Lt.wav" \
-map "[R]" "${f%.*}_EXTRACTED_Rt.wav"; done

cli tree met find

find

find -maxdepth 2 -type d -ls | sed -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' > tree.txt

in tree text file
--test
----test.git
--apps
----namefile1.git
----namefile2.git

ls

ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'

|-folder
|---dir
|---dir2

find with grep

grep -rnw '/path/to/somewhere/' -e 'pattern'

include

grep --include=\*.{c,h} -rnw '/path/to/somewhere/' -e "pattern"

exclude

grep --exclude=\*.o -rnw '/path/to/somewhere/' -e "pattern"

with dir

grep --exclude-dir={dir1,dir2,*.dst} -rnw '/path/to/somewhere/' -e "pattern"
Tags: 

speedtest cli

curl -s https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py | python -

Cli with java commons

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>testffCli</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>
    <dependencies>
        <dependency>
            <groupId>commons-cli</groupId>
            <artifactId>commons-cli</artifactId>
            <version>1.4</version>
        </dependency>
    </dependencies>
    <build>
        <finalName>Cli</finalName>
    </build>
</project>

Cli.java

import org.apache.commons.cli.*;
import java.io.PrintWriter;

public class Cli {
    private static final Option ARG_ADD = new Option("a", "addition", false, "Add numbers together.");
    private static final Option ARG_SUBTRACT = new Option("s", "subtract", false, "Subtracts numbers together.");
    private static final Option ARG_MULTIPLY = new Option("m", "multiply", false, "Multiply numbers together.");
    private static final Option ARG_DIVIDE = new Option("d", "divide", false, "Divide numbers together.");

    public static void printHelp(Options options) {
        HelpFormatter hf = new HelpFormatter();
        PrintWriter pw = new PrintWriter(System.out);
        pw.println("Math App " + Cli.class.getPackage().getImplementationVersion());
        pw.println();
        hf.printUsage(pw, 100, "java -jar Cli.jar [OPTIONS] Number Number");
        hf.printOptions(pw, 100, options, 2, 5);
        pw.close();
    }

    public static void main(String[] args) {

        CommandLineParser clp = new DefaultParser();
        Options options = new Options();
        options.addOption(ARG_ADD);
        options.addOption(ARG_SUBTRACT);
        options.addOption(ARG_MULTIPLY);
        options.addOption(ARG_DIVIDE);

        try {
            CommandLine cl = clp.parse(options, args);

            if (cl.getArgList().size() < 2) {
                printHelp(options);
                System.exit(-1);
            }

            var a = Integer.parseInt(cl.getArgList().get(0));
            var b = Integer.parseInt(cl.getArgList().get(1));

            if (cl.hasOption(ARG_ADD.getLongOpt())) {
                System.out.println(String.format("%1$d + %2$d = %3$d", a, b, (a + b)));
            } else if (cl.hasOption(ARG_SUBTRACT.getLongOpt())) {
                System.out.println(String.format("%1$d - %2$d = %3$d", a, b, (a - b)));
            } else if (cl.hasOption(ARG_MULTIPLY.getLongOpt())) {
                System.out.println(String.format("%1$d * %2$d = %3$d", a, b, (a * b)));
            } else if (cl.hasOption(ARG_DIVIDE.getLongOpt())) {
                System.out.println(String.format("%1$d / %2$d = %3$d", a, b, (a / b)));
            } else {
                printHelp(options);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
Tags: 

Remove all node_module folders

find . -name "node_modules" -type d -prune | xargs du -chs
find . -name "node_modules" -type d -prune -exec rm -rf '{}' +

Isolate folder containerize manually

in linux env

mkdir jail  
sudo cp /bin/bash ./jail/  
tree jail  
ldd /bin/bash # see the dep of bash program  
mkdir /jail/lib64  
sudo cp /lib64/lininfo.so.6 jail/lib64 // etc 5c  
tree jail  
chroot /root/jail/ ./bash // !!!  

Add new remote on github from cli

curl -u 'USER' https://api.github.com/user/repos -d '{"name":"PROJNAME"}'

Windows cli check for running at port 1234

netstat -ano | findstr :<PORT>
tskill typeyourPIDhere 
or taskkill /PID 14328 /F

scan local network

sudo nmap -sn 192.168.1.0/24 > ~/Desktop/nmaplog.txt

git remove sensitive data from history in files

git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch path_to_file" HEAD
It’s a time intensive task might takes good amount of time to complete. As it has to check each commit and remove.
If you want to push it to remote repo just do git push
git push -all

Tags: 

curl statuscode

to get via curl a statuscode

curl -I www.website.com

Subscribe to RSS - cli