Skip to content

Instantly share code, notes, and snippets.

Avatar
🤙
What's a github status?

Yuval Greenfield ubershmekel

🤙
What's a github status?
View GitHub Profile
@ubershmekel
ubershmekel / sort-youtube-bookmarklet.js
Last active Mar 27, 2021
Paste the following into a bookmark. When you're on a youtube channel's video page, you can now sort that page by view count.
View sort-youtube-bookmarklet.js
javascript: function findMetrics(el) {
return el.textContent;
}
function findNodes(el) {
return el.querySelectorAll('#metadata-line.ytd-grid-video-renderer');
}
function metricVal(el) {
let modifiers = {
@ubershmekel
ubershmekel / arraydiff.js
Created Dec 2, 2020
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.
View arraydiff.js
/*
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
View generate_ids.py
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 Oct 14, 2019
Crunchbase hides search results behind a darker element and blurs the rows. This removes that.
View remove-crunchbase-overlay.js
// 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 Jul 22, 2019
An example race condition in JavaScript
View race-condition.js
// 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 Apr 23, 2018
See alt descriptions js console snippet
View show-alts.js
// 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 Mar 15, 2020
Trigger a google analytics (new or old) and a pixel event
View eventAll.js
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 Jun 22, 2017
How to open .sgn file types from Israeli Courts
View open_sgn.py
#!/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 Mar 8, 2017
Pile of images positioned randomly
View pile.py
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 Apr 21, 2020
Simple unicode keyboard automation for windows
View windows_keys.py
# 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