Skip to content

Instantly share code, notes, and snippets.

View kopiro's full-sized avatar

Flavio Maria De Stefano kopiro

View GitHub Profile
@kopiro
kopiro / permutations.js
Last active February 25, 2021 14:48
UNIQUE Permutations ES6 Generators
const permutations = function*(elements, map = new Map()) {
if (elements.length === 1) {
yield elements;
} else {
const [first, ...rest] = elements;
for (const perm of permutations(rest, map)) {
for (let i = 0; i < elements.length; i++) {
const start = perm.slice(0, i);
const rest = perm.slice(i);
const val = [...start, first, ...rest];
@kopiro
kopiro / sync-code-projects.sh
Created October 7, 2020 17:50
Sync your ~/Projects directories with VSCode Project Manager extension
sync-code-projects() {
CODE_PROJECTS_FILE="$HOME/Library/Application Support/Code/User/projects.json" && \
echo "[" > "$CODE_PROJECTS_FILE" && \
find ~/Projects \
-maxdepth 1 \
-type d \
-execdir echo "{ \"name\": \"{}\", \"rootPath\": \"$HOME/Projects/{}\", \"enabled\": true }," >> "$CODE_PROJECTS_FILE" \; &&
echo "{}]" >> "$CODE_PROJECTS_FILE"
}
@kopiro
kopiro / fb-photo-album-download.js
Last active February 2, 2023 06:21
Download all the photos of a Facebook Album / "Photos of you"
/*
Download all the photos of a Facebook Album / "Photos of you"
If you want to download "the photos that you uploaded",
use the simpler "Your Facebook Information" feature on https://www.facebook.com/settings?tab=your_facebook_information
This script is only useful to download the photos you've been tagged into
You can find this page on: https://www.facebook.com/photos
Make sure you scroll 'til the end of the page, and then paste it into the console
@kopiro
kopiro / yarn-x.sh
Last active July 29, 2020 13:27
Yarn run fuzzy matching
pkgj-run-list() {
jq .scripts package.json | grep -o '.*\":' | sed -nE 's/\"(.*)\":/\1/p' | awk '{$1=$1};1' | fzf | tr -d '\r' | tr -d '\n'
}
yarn-x() {
PKG_CMD=$(pkgj-run-list)
[ -n "$PKG_CMD" ] && print -s "yarn $PKG_CMD" && yarn "$PKG_CMD"
}
alias yx="yarn-x"
@kopiro
kopiro / xhr_fetch_hook.js
Last active June 16, 2020 08:32
XHR / Fetch Hook - Log requests directly in the Dev Console
formatBody = (body) => { if (!body) return body; try { return JSON.parse(body); } catch (err) { return body; } };
XMLHttpRequest.prototype._open = XMLHttpRequest.prototype._open || XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function() {
this._openArgs = arguments;
return XMLHttpRequest.prototype._open.apply(this, arguments);
};
XMLHttpRequest.prototype._send = XMLHttpRequest.prototype._send || XMLHttpRequest.prototype.send;
XMLHttpRequest.prototype.send = function(body) {
@kopiro
kopiro / file.sh
Last active March 31, 2020 15:45
Configure Unattended Upgrades
apt-get -y install unattended-upgrades
dpkg-reconfigure --priority=low unattended-upgrades
@kopiro
kopiro / slack-multiple.scpt
Created September 23, 2019 12:20
Slack - Multiple channels message
set myChannels to {"random"} # Populate this field
set theResponse to display dialog "What's your message?" default answer "" with icon note buttons {"Cancel", "Continue"} default button "Continue"
set theMessage to text returned of theResponse
tell application "Slack"
activate
tell application "System Events"
repeat with theChannel in myChannels
@kopiro
kopiro / get-apple-id-email.sh
Last active June 19, 2019 12:39
Get Apple ID email in OSX
#!/bin/sh
dscl . readpl "/Users/$(whoami)" dsAttrTypeNative:LinkedIdentity "appleid.apple.com:linked identities:0:full name" | awk '{print $4}'
@kopiro
kopiro / AutoUpdater.vb
Created November 26, 2018 08:10
Auto Update VB.NET Compact 3.5 App
Public Class AutoUpdater
Public newVersion As String
Public urlOfCab As String
Public credentials As Net.NetworkCredential
Public askDest As Boolean = False
Public deleteCab As Boolean = True
Public useUI As Boolean = False
Public permitUninstall As Boolean = False
@kopiro
kopiro / README.md
Last active November 6, 2018 14:39
Extract from a JS object with a specific pattern

extractWithPattern

Extract from a JS object with a specific pattern

let msg = [
	{ payload: { errors: { unknown_language: 'hello' } } },
	{ payload: { errors: { number: 1 } } },
	{ randomstuff: 42 }
];