Skip to content

Instantly share code, notes, and snippets.

View l-portet's full-sized avatar
🤙

Lucas Portet l-portet

🤙
View GitHub Profile
@l-portet
l-portet / gist:28882743b683618e599609c9193b29aa
Last active November 8, 2018 15:28 — forked from guilherme/gist:9604324
Git pre-commit hook that detects if the developer forget to remove all the javascript debugger before commit.
#!/bin/sh
# Redirect output to stderr.
exec 1>&2
# enable user input
exec < /dev/tty
debugregexp='debugger'
# CHECK
if test $(git diff --cached | grep $debugregexp | wc -l) != 0
then
@l-portet
l-portet / kill-port.fish
Created July 3, 2020 16:30
Fish function that kill the process listening on a specific port
# Fish function that kill the process listening on a specific port
# Usage: kill-port <port>
function kill-port
lsof -n -i:$argv | grep LISTEN | awk '{ print $2 }' | uniq | xargs kill -9
end
@l-portet
l-portet / array_chunk.js
Created January 6, 2021 10:34
Split & stack an array into chunks
// Split & stack an array into chunks
// Ex: arrayChunk([1, 2, 3, 4, 5, 6, 8], 3) => [[1, 2, 3], [4, 5, 6], [7, 8]]
function arrayChunk (arr = [], len = 2, stackRest = false) {
const chunks = [];
const n = arr.length;
let i = 0;
while (i < n) {
const chunk = arr.slice(i, i += len);
@l-portet
l-portet / custom-window-properties.js
Created May 17, 2021 22:17
Find all the custom properties created in the window object. Very useful to debug or reverse engineer a web app.
(() => {
let results;
let currentWindow;
let customizedWindow = {};
let iframe = document.createElement('iframe');
iframe.style.display = 'none';
document.body.appendChild(iframe);
currentWindow = Object.getOwnPropertyNames(window);
results = currentWindow.filter(function (prop) {
return !iframe.contentWindow.hasOwnProperty(prop);
@l-portet
l-portet / slog.js
Last active July 6, 2021 20:46
Client-side silent log
window.slog = function (...args) {
if (!window.logsStack) {
window.logsStack = [];
window.printLogsStack = function () {
for (const logItem of window.logsStack) {
const [msg, lineDetails] = logItem;
console.log(msg);
console.log(lineDetails);
}
@l-portet
l-portet / vuex-global-mutation.js
Last active August 26, 2022 07:24
Edit all nested props of a Vuex state with a single mutation
// Usage:
// commit ('SET', { prop: `path.to['my'].prop[1]`, value: 42 });
// or commit ('SET', [`path.to['my'].prop[1]`, 42]);
export default {
SET_PROP(state, payload) {
let prop, value;
if (Array.isArray(payload)) {
[prop, value] = payload;
@l-portet
l-portet / airbnb-price-per-person.js
Created December 24, 2021 17:22
Show the total price per person of an Airbnb listing
// Script that shows the total price of an Airbnb listing divided by the number of persons
// Inject it in any Airbnb search page (https://airbnb.com/s/*)
!function() {
function runner() {
const persons = +new URL(window.location.href).searchParams.get('adults');
if (!persons) {
return;
}
@l-portet
l-portet / foobar-challenge.js
Created July 31, 2022 21:19
Check if there's any Google foobar challenge invite in the page comments
// Check if there's any Google foobar challenge invite in the page comments
// https://www.geeksforgeeks.org/google-foo-bar-challenge/
(() => {
function getAllComments() {
const $root = document.documentElement;
const comments = [];
const iterator = document.createNodeIterator($root, NodeFilter.SHOW_COMMENT, () => NodeFilter.FILTER_ACCEPT, false);
let node;
while (node = iterator.nextNode()) {
@l-portet
l-portet / cursor-emoji.scss
Last active August 6, 2022 22:38
SCSS mixin to use an emoji as a cursor
@mixin cursor-emoji($emoji) {
cursor: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='40' height='48' viewport='0 0 100 100' style='fill:black;font-size:24px;'><text y='50%'>"+$emoji+'</text></svg>')
16 0,
auto;
}
@l-portet
l-portet / find-all-props.js
Created August 26, 2022 07:22
Find all properties & methods of an object, up to the root prototype
// Find all properties & methods of an object, up to the root prototype
function findAllProps(obj, props = []) {
if (!obj) {
return props;
}
return findAllProps(Object.getPrototypeOf(obj), [
...props,
Object.getOwnPropertyNames(obj),
]);
}