Skip to content

Instantly share code, notes, and snippets.

View florianpasteur's full-sized avatar

Florian PASTEUR florianpasteur

View GitHub Profile
PS1="\[\033[01;37m\]\$? \$(if [[ \$? == 0 ]]; then echo \"\[\033[01;32m\]\342\234\223\"; else echo \"\[\033[01;31m\]\342\234\227\"; fi) $(if [[ ${EUID} == 0 ]]; then echo '\[\033[01;31m\]\h'; else echo '\[\033[01;32m\]\u@\h'; fi)\[\033[01;34m\] \w \$\[\033[00m\] "
@florianpasteur
florianpasteur / docker-tools.sh
Last active September 10, 2020 08:39
docker tools
dexec() { docker exec -ti "$1" bash; }
dfind () { docker ps | grep "$1" | cut -d " " -f1; }
dafind () { docker ps -a | grep "$1" | cut -d " " -f1; }
@florianpasteur
florianpasteur / generate-ssh-key-github.md
Last active November 23, 2020 18:23
Generate SSH key for Github
@florianpasteur
florianpasteur / readme.md
Last active December 2, 2023 20:16
Hackjam.io
@florianpasteur
florianpasteur / port-usage.sh
Created November 2, 2020 10:35
find port usage by process
netstat -vanp tcp | grep -E "pid|3000"
@florianpasteur
florianpasteur / findElement.ts
Last active January 14, 2021 10:42
Find html element by text
function findElement(text: string, searchStart: Node = document.body): HTMLElement {
return document
.evaluate(
"//*[text()='" + text + "']",
searchStart,
null,
XPathResult.ANY_TYPE,
null
)
.iterateNext() as HTMLElement;
@florianpasteur
florianpasteur / search_and_reaplce.js
Created February 3, 2021 15:16
Surprising Search & Replace in JS
tag = "Some value";
replacetag = '<span class="hightlighttag">' + tag + '</span>';
console.log(textarea.value.split(tag).join(replacetag))
@florianpasteur
florianpasteur / optional.ts
Created March 1, 2021 16:13
Null-safe Optional with Typescript
// Example type
type UserInfo = {
username: string,
email: string
};
type Present<T> = { exists: true, value: T };
type Absent = {exists: false};
type Optional<T> = Present<T> | Absent;
@florianpasteur
florianpasteur / optional.ts
Last active March 16, 2021 09:34
Typescript Optional
// Example type
type UserInfo = {
username: string,
email: string
};
type Present<T> = {
exists: true,
value: T
};
@florianpasteur
florianpasteur / browser-automation-toolbox.js
Last active September 21, 2021 14:36
Browser Automation Toolbox
// Sources: https://gist.github.com/florianpasteur/118d0e29313c3fb052f944bc001cde88
function findElementByText(text, searchStart = document.body, _document = document, ignoreSpace = false) {
return _document
.evaluate(
`//*[${ignoreSpace ? 'normalize-space' : 'text'}()="${text}"]`,
searchStart,
null,
XPathResult.ANY_TYPE,
null