Skip to content

Instantly share code, notes, and snippets.

View ubershmekel's full-sized avatar
🤙
What's a github status?

Yuval Greenfield ubershmekel

🤙
What's a github status?
View GitHub Profile
@ubershmekel
ubershmekel / arraydiff.js
Created December 2, 2020 23:57
From 2020-11-29 cassidy@cassidoo.co 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.
/*
From 2020-11-29 cassidy@cassidoo.co 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
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',
@ubershmekel
ubershmekel / remove-crunchbase-overlay.js
Created October 14, 2019 01:21
Crunchbase hides search results behind a darker element and blurs the rows. This removes that.
// 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", "") })
@ubershmekel
ubershmekel / race-condition.js
Created July 22, 2019 07:07
An example race condition in JavaScript
// 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;
@ubershmekel
ubershmekel / show-alts.js
Last active April 23, 2018 09:33
See alt descriptions js console snippet
// 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");
@ubershmekel
ubershmekel / eventAll.js
Last active March 15, 2020 23:04
Trigger a google analytics (new or old) and a pixel event
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', {
@ubershmekel
ubershmekel / open_sgn.py
Created June 22, 2017 00:00
How to open .sgn file types from Israeli Courts
#!/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
@ubershmekel
ubershmekel / pile.py
Created March 8, 2017 19:53
Pile of images positioned randomly
import glob
import random
from PIL import Image
from tqdm import tqdm
images = glob.glob('pngs2/*.png')
width = 700
height = 700
@ubershmekel
ubershmekel / windows_keys.py
Last active October 18, 2021 07:04
Simple unicode keyboard automation for windows
# 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
@ubershmekel
ubershmekel / concat.py
Created January 22, 2017 23:06
Concatenate a few video files into one with ffmpeg
"""
Concatenate a few video files into one with ffmpeg
Use a wild card
"""
import subprocess
import glob
import re
to_concat = 'robocar*'