Skip to content

Instantly share code, notes, and snippets.

@nestoralonso
nestoralonso / convert-all.sh
Created February 24, 2023 23:00
convert pngs to jpgs using xargs
ls -1 *.png | xargs -n 1 bash -c 'convert "$0" "${0%.png}.jpg" && rm "$0"'
@nestoralonso
nestoralonso / use-proxy.js
Created September 8, 2021 15:25
Make node use the OS Proxy
const proxy = require('node-global-proxy').default;
// For charles proxy
proxy.setConfig("http://127.0.0.1:8888");
proxy.start();
@nestoralonso
nestoralonso / jq-example.sh
Last active August 27, 2021 18:22
JQ Example
curl https://api.github.com/repos/mrdoob/three.js/issues?per_page=100 | \
jq 'map({ title: .title, number: .number, labels: .labels | length }) | \
map(select(.labels > 0))'
# array constructor
jq '[ .[] | { title: .title, number: .number, labels: .labels | length } ]'
@nestoralonso
nestoralonso / dateSufix.js
Created August 11, 2021 20:59
formats curr date as str (useful for naming new files)
const formatDateAsString = date => {
const fmt = new Intl.NumberFormat('en-US', {
minimumIntegerDigits: 2,
useGrouping: false,
});
const dateStr = [date.getFullYear(), date.getMonth() + 1, date.getDate()]
.map(fmt.format)
.join('');
const time = [date.getHours(), date.getMinutes()]
.map(fmt.format)
@nestoralonso
nestoralonso / list-durations
Created May 6, 2021 20:50
List Durations of Video Files, requires java >=11 and ffprobe
#!/usr/bin/env java --source=11
import java.util.List;
import java.io.IOException;
import java.io.InputStreamReader;
import java.time.Duration;
import java.io.BufferedReader;
import java.util.ArrayList;
import java.util.Collection;
class ListDurations {
@nestoralonso
nestoralonso / range.js
Created March 9, 2021 18:57
Generates an array containing the interval [lower, max) a la python
// Generates an array containing the interval [lower, max) a la python
const range = (lower, max) => Array.from({ length: max - lower }, (x, i) => lower + i);
@nestoralonso
nestoralonso / traverse.js
Created January 27, 2021 19:34
Traverse the values of an object
function traverse(obj, callback) {
const stack = [];
stack.push(obj);
while (stack.length) {
const current = stack[0];
for (const key of Object.keys(current)) {
if (current[key] != null && typeof current[key] === 'object') {
stack.push(current[key]);
@nestoralonso
nestoralonso / config.yml
Created January 19, 2021 15:37
Config file to make dependabot less spammy? not yet tested .dependabot/config.yml
version: 1
update_configs:
- package_manager: "javascript"
directory: "/"
update_schedule: "weekly"
default_labels:
- "dependencies"
automerged_updates:
- match:
update_type: "in_range"
@nestoralonso
nestoralonso / createElement.js
Created September 28, 2020 16:35
Creates a dom object node passing it the attributes
function createElem(name, attrs) {
const elem = document.createElement(name);
return Object.assign(elem, attrs);
}
// Example usage
const newDiv = createElem('div', { className: 'lol', style: 'width: 100px'})
@nestoralonso
nestoralonso / unused-branches.sh
Last active September 3, 2020 17:36
Unused Branches
for k in $(git branch -r --merged| sed /\*/d | egrep -v "(^\*|master|dev)"); do
if [ -n "$(git log -1 --before='2 weeks ago' -s $k)" ]; then
echo $k
fi
done