This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
From 2020-11-29 [email protected] newsletter challenge | |
Given an array of integers and a target value, return the number of pairs of array | |
elements that have a difference equal to a target value. | |
Examples: | |
$ arrayDiff([1, 2, 3, 4], 1) | |
$ 3 // 2 - 1 = 1, 3 - 2 = 1, and 4 - 3 = 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import glob | |
import os | |
unknown_location_acronym = 'tbd' | |
# https://gist.github.com/rogerallen/1583593 | |
us_state_to_abbrev = { | |
'Alabama': 'AL', | |
'Alaska': 'AK', | |
'American Samoa': 'AS', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// E.g used on | |
// https://www.crunchbase.com/search/principal.investors/8ff469dfad43f418bb327da3508ebddf | |
// Crunchbase hides search results behind a darker element and blurs the rows. This removes that | |
// so you can see the top 15 results instead of just 5. Though you won't be able to see beyond that. | |
document.querySelector('.all-results-upsell-wrapper').remove() | |
document.querySelectorAll('grid-row').forEach((it) => { it.setAttribute("class", "") }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// An example race condition in JavaScript | |
// When you run this script using Node or in a browser, you'll find it | |
// does not print "Ended with 0", but a random number. Even though the functions running | |
// simply loop 100 iterations of adding and subtracting. The reason the end result is random | |
// is because the sleeps are of random duration and the time between the read of the variable | |
// causes the eventual write to be incorrect when `adder` and `subber` interleave. | |
// This problem is similar to https://en.wikipedia.org/wiki/Time-of-check_to_time-of-use | |
let number = 0; | |
const times = 100; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Paste the following into your js console while viewing images, e.g. on your facebook feed. | |
// It will show the "alt" attributes that facebook assigned your images. | |
// It's an interesting peek into how facebook analyzes your images. | |
setInterval(function() { | |
var imgs = document.querySelectorAll("img"); | |
for (var i = 0; i < imgs.length; i++) { | |
var alt = imgs[i].alt; | |
if (alt && !imgs[i].getAttribute("alted")) { | |
var div = document.createElement("div"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function eventAll(eventName) { | |
// https://support.google.com/analytics/answer/1033068?hl=en | |
// non_interaction/nonInteraction to avoid raising bounce rate | |
// when there's an event that fires every page load. | |
if (window.gtag) { | |
gtag('event', eventName, { | |
non_interaction: true, | |
}); | |
} else if (window.ga) { | |
ga('send', { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
""" | |
court.gov.il for some reason send out these signed files with the "sgn" file extension. | |
They're xml files with base64 encoded contents, this is how you can get them out. | |
open_sgn.py myfile.sgn | |
""" | |
import base64 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import glob | |
import random | |
from PIL import Image | |
from tqdm import tqdm | |
images = glob.glob('pngs2/*.png') | |
width = 700 | |
height = 700 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
import ctypes | |
import time | |
import sys | |
LONG = ctypes.c_long | |
DWORD = ctypes.c_ulong | |
ULONG_PTR = ctypes.POINTER(DWORD) | |
WORD = ctypes.c_ushort |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Concatenate a few video files into one with ffmpeg | |
Use a wild card | |
""" | |
import subprocess | |
import glob | |
import re | |
to_concat = 'robocar*' |