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 / 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 / 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 / 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 / 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", "") })
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 / arraydiff.js
Created December 2, 2020 23:57
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.
/*
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
@ubershmekel
ubershmekel / sort-youtube-bookmarklet.js
Last active August 5, 2024 05:08
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. This new version works with the 2022 UI refresh that added rows to the mix.
javascript: function findNodes(el) {
return el.querySelectorAll('#metadata-line');
}
function isDigit(str) {
return str.length === 1 && str.match(/[0-9]/i);
}
function metricVal(el) {
let modifiers = {
@ubershmekel
ubershmekel / collatzc.py
Created August 1, 2021 15:30
Trying to symbolically solve the Collatz Conjecture
"""
The Simplest Math Problem No One Can Solve - YouTube - https://www.youtube.com/watch?v=094y1Z2wpJg
Collatz Conjecture
3x + 1
x / 2
(3x + 1) / 2 = 1.5x + 0.5
3(x/2) + 1 = 1.5x + 1
@ubershmekel
ubershmekel / collatz.v
Last active August 9, 2021 21:28
Symbolically searching for a counter-example to the Collatz Conjecture. A more efficient version of collatzc.py, written in vlang, evaluates 1e6 paths per second. Note you must edit vlang to make fractions expose their n and d, see https://github.com/vlang/v/pull/11018
// The Simplest Math Problem No One Can Solve
// https://www.youtube.com/watch?v=094y1Z2wpJg
// https://en.wikipedia.org/wiki/Collatz_conjecture
// I'm looking for loops by checking every positive integer (1, 2, 3...)
// and I'm using the binary representation (0b0, 0b10, 0b11, 0b100, ...)
// as an up and down path of a collatz loop where '1' means (3x+1)/2 and
// '0' means x/2 . `frac_follow_path` calculates what should be the starting
// value based on that collatz loop path, and if that's an integer -
// we found a loop.
// Problems so far:
@ubershmekel
ubershmekel / see-commit-durations.js
Created October 4, 2021 03:41
Paste this in the JS console when looking at github commit history
dateEls = [...document.querySelectorAll('relative-time')]
dates = dateEls.map(it => new Date(it.attributes['datetime'].textContent));
durations = [];
for (const [i, dt] of dates.entries()) {
const hours = Math.round((dates[i] - dates[i + 1]) / 3600e2) / 10;
const newNode = document.createTextNode("- took hours " + hours);
dateEls[i].parentNode.appendChild(newNode);
durations.push(hours)
}