Skip to content

Instantly share code, notes, and snippets.

View VehpuS's full-sized avatar
🦔

Moshe Jonathan Gordon Radian VehpuS

🦔
View GitHub Profile
@VehpuS
VehpuS / sql-select-by-value-in-array.sql
Last active April 25, 2024 07:56
SQL select by value in a array
SELECT id, column FROM table
where id::VARCHAR = ANY (ARRAY['b329a9b1-54fb-4d5e-853e-4c58555ab0de', 'fc666e0a-0dd1-4d02-990c-4ae52324da36'])
@VehpuS
VehpuS / testOpenApi.ts
Last active October 22, 2023 13:00
Test openapi operations schema before calling an endpoint
import { compact, every, includes, isEmpty, map, some } from 'lodash';
interface OpenAPIOperation {
path: string;
action: 'get' | 'post' | 'put' | 'delete';
parameters: string[];
}
function checkOpenApiForOps(
openApiJson: any,
@VehpuS
VehpuS / enum_values.ts
Created March 21, 2023 09:52
Programmatically get enum keys / values in TypeScript
// Playground URL: https://www.typescriptlang.org/play?#code/KYOwrgtgBAKsDOAXKBvAUFTUCGUC8UARAIKEA0GWARvkQELmWYDGtAjBQL5prMD2IeHwA2wAHTC+AcwAUhAKLhoAa2ABPeOSgB5KgCtgzRGNUaZcJAEoxAMwCWwxMABOMmQDdL+AHxQ78ADlsAJkAyCoXD0toyx4bMBAjOwEoUEgANWxhMAQAGX9EAB4YVIAPJxAAE3hUTm8ZNIgYPgBhAXcXRAAuWEsemABtUz4bWABdAbHUJih+QWRTGoJdAyMTdXgGpWa2kA7nRGt7R0ionz9A4NDwyM9ogG4Z52BEMGcQKEWxCGwABxllOdGjt2p0hjgasNRjAxpZHtxeAIkFAnEhMtkEP0EIhJrRGuicvB8khzNi4Tw5kJRBJpHJFJAoO4soStKjEASEOSgA
enum Test {
a = "A",
b = "B",
c = 1,
}
console.log("Enum keys", Object.keys(Test).filter((v) => isNaN(Number(v))))
@VehpuS
VehpuS / react-dependences.md
Created February 7, 2023 19:01
Awesome dependencies visualization for a react project

Visualizing React Project Dependencies

Based on this article.

Setup

npm install --save-dev dependency-cruiser
choco install graphviz
@VehpuS
VehpuS / saveAllImgTagSourcesFromWebpage.js
Created January 9, 2023 14:56
How to save all <img> elements from a website
Array.from(document.querySelectorAll("img")).forEach((img) => {
const save = document.createElement('a');
save.href = img.src;
save.target = '_blank';
save.click();
});
@VehpuS
VehpuS / xml_node.py
Last active April 21, 2024 11:07
A helper class to make navigating xml files in python nicer (for someone unused to the python parser :P). My way of becoming more "fluent" with XML in python, and may be useful for other people / provide a good demo for safe recursion in Python, recursive types...
from __future__ import annotations
from typing import Any, Dict, List, NamedTuple, Union
import xml.etree.ElementTree as ET
class XmlNode(NamedTuple):
'''A helper class to make navigating xml files in python nicer and to create virtual XML nodes that can be saved'''
tag: str
attrib: Dict[str, Any]
@VehpuS
VehpuS / client_side_loop.py
Created December 7, 2022 13:25
A small demonstration of Python client side loop over Google Earth Engine objects (instead of using .map which can only run server side code)
import ee
image_col = ee.ImageCollection(...) # This should work with FeatureCollections and other GEE iterables
img_list = image_col.toList(image_col.size())
for img_idx in range(0, image_col.size().getInfo()):
img = ee.Image(img_list.get(img_idx))
...
@VehpuS
VehpuS / hackernewsGetUserUpvotesDevConsole.js
Last active November 30, 2022 13:27
Scraping personal YCombinator hackernews upvotes from the developer console after login (running in dev console adds the relevant cookie info). Can easily be adapted to an independent scraper / work for more than just the URL
/**
* Get a list of all upvotes urls for a user from a single page
* @param {string} user - The logged in username (you won't be able to get a response for another user)
* @param {number} pageNum - The page of upvotes to query
* @returns {Promise<string[]>} a list of upvoted URLs from the page
*/
const queryUserUpvotesByPage = async (user, pageNum) => {
const req = await fetch(`https://news.ycombinator.com/upvoted?id=${user}&p=${pageNum}`);
const text = await test.text();
return Array.from(text.matchAll(/titleline.*?a href\="(.*?)"/g)).map(([t, url]) => url);
@VehpuS
VehpuS / run_os_cmd.py
Last active April 21, 2024 11:07
Run bash command from python
import subprocess
import sys
def run_os_cmd(
cmd: str, # Command to run
interactive_write: bool=True, # Should the command print as it's running
):
print(f"Running '{cmd}'")
cmd_proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True )
@VehpuS
VehpuS / birthday.sh
Created October 27, 2022 13:06
Birthday wishes in bash
#!/bin/bash
let x=0;until ((x==120)); do let x+=1;echo $x;done