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 / main.dart
Last active September 28, 2023 03:00
Test a stackoverflow solution. It doesn't work
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:flutter/material.dart';
import 'dart:ui';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@ubershmekel
ubershmekel / main.dart
Created September 26, 2023 06:08
Word wrapping text labels is hard
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
@ubershmekel
ubershmekel / sort-youtube-comments-bookmarklet.js
Last active April 5, 2023 02:08
On a video page, run this in the console, or click the bookmarklet, to have the comments sorted by their upvotes
javascript: function findNodes(el) {
return el.querySelectorAll('#vote-count-middle');
}
function isDigit(str) {
return str.length === 1 && str.match(/[0-9]/i);
}
function metricVal(el) {
let modifiers = {
@ubershmekel
ubershmekel / monaco-highlight-finder.js
Last active October 12, 2022 16:52
This is slow, but it works, to find the text that's highlighted by a monaco editor
// Paste this into JS to find an ACE editor in your browser window
// Based off of https://stackoverflow.com/questions/12102425/recursively-search-for-a-value-in-global-variables-and-its-properties/12103127#12103127
function isTarget(obj) {
// return typeof obj == typeof value && obj == value
if (obj && obj['getModel'] && obj.getModel() && obj.getModel().getValueInRange) {
const highlight = obj.getModel().getValueInRange(obj.getSelection())
if (highlight) {
console.log('highlight', highlight);
return true;
}
@ubershmekel
ubershmekel / find_ace.js
Last active October 12, 2022 10:41
Find an ace editor in your window or any other object
// Paste this into JS to find an ACE editor in your browser window
// Based off of https://stackoverflow.com/questions/12102425/recursively-search-for-a-value-in-global-variables-and-its-properties/12103127#12103127
function isTarget(obj) {
// return typeof obj == typeof value && obj == value
return obj && obj['getSelectedText'];
}
function globalSearch(startObject, isTargetFunc) {
var stack = [[startObject, '']];
var searched = [];
var found = false;
@ubershmekel
ubershmekel / sort-hackernews.js
Created January 17, 2022 21:32
Sort the front page of hacker news by score with this bookmarklet. Save it as a bookmark.
javascript: function findNodes(el) {
return el.querySelectorAll('.score');
}
function isDigit(str) {
return str.length === 1 && str.match(/[0-9]/i);
}
function metricVal(el) {
let modifiers = {
@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)
}
@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 / 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 / sort-youtube-bookmarklet.js
Last active February 1, 2023 01:24
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 findMetrics(el) {
return el.textContent;
}
function findNodes(el) {
return el.querySelectorAll('#metadata-line');
}
function isDigit(str) {
return str.length === 1 && str.match(/[0-9]/i);