Skip to content

Instantly share code, notes, and snippets.

View matthewpoer's full-sized avatar

Matthew Poer matthewpoer

View GitHub Profile
#!/usr/bin/env python3
import requests
f=o=i=p=""
while not (f and o and i and p):
for word in requests.get("https://random-word-api.herokuapp.com/word?lang=en&number=50").json():
if word[0] == "f":
f = word
if word[0] == "o":
o = word
if word[0] == "i":
@matthewpoer
matthewpoer / Python Queue Demo.log
Last active March 13, 2023 19:27
Queue up some sleep statements and print which ones finish in what order. Demonstrates doing so with Queues, Threads, and ThreadPoolExecutor Futures. Notice that we enqueue the "15" before the "6" but of course the sleep(6) finishes well before the sleep(15)
Started worker and queued sleeper 3 ... 0.00016
running worker for 3 ... 0.00063
Started worker and queued sleeper 9 ... 0.00069
running worker for 9 ... 0.00107
Started worker and queued sleeper 15 ... 0.0011
running worker for 15 ... 0.00145
Started worker and queued sleeper 12 ... 0.00151
running worker for 12 ... 0.0018
Started worker and queued sleeper 6 ... 0.00192
running worker for 6 ... 0.0022
@matthewpoer
matthewpoer / EmptyUpdateBatch.cls
Last active November 16, 2022 19:19
Class to batch update records but make not changes. Useful to trigger a flow to take effect on existing data that writes a new field. Replace !!ObjectType!! with your object, e.g. Contact or Lead or CustomObject__c
global class EmptyUpdateBatch implements Database.Batchable<sObject> {
global Database.QueryLocator start(Database.BatchableContext BC) {
String query = 'SELECT Id FROM !!ObjectType!! WHERE Field = NULL';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<!!ObjectType!!> records) {
update records;
}
global void finish(Database.BatchableContext BC) {}
}
@matthewpoer
matthewpoer / py_merge_docu
Created December 17, 2021 15:30
demo python object merge method
matthewpoer@magpie sdp % python3
Python 3.9.7 (default, Oct 13 2021, 06:45:31)
[Clang 13.0.0 (clang-1300.0.29.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> object_one = {"primary key":"super duper"}
>>> object_two = {"primary key":"override", "additional key":"so fun"}
>>> object_one.update(object_two)
>>> object_one
{'primary key': 'override', 'additional key': 'so fun'}
import time
barList = ["|","/","-","\\"]
barListIter = iter(barList)
ten_seconds_away = int(time.time()) + 10
while int(time.time()) < ten_seconds_away:
remaining = ten_seconds_away - int(time.time())
bar = next(barListIter, None)
if not bar:
barListIter = iter(barList)
bar = next(barListIter)
@matthewpoer
matthewpoer / object safe get.py
Created October 4, 2021 15:46
The safest `get()` method
bugs = {
"FirstName": "Bugs",
"LastName": "Bunny",
"Hometown": {
"City": "Los Angeles",
"State": "California",
"Country": {
"ISO": "US",
"Text": "United States",
},
@matthewpoer
matthewpoer / fix-installed-packages-metdata.sh
Created August 30, 2021 13:19
installedPackages activateRSS fixup
# only for the Mac folks so we can `sed` like a real boy
brew install gnu-sed
PATH="$(brew --prefix)/opt/gnu-sed/libexec/gnubin:$PATH"
# props to Gearset's blog
# https://gearset.com/blog/installed-packages-v43-and-activaterss/
cd force-app/main/default/installedPackages
sed -i 's/ xsi:nil="true"\/>/>false<\/activateRSS>/g' *xml
cd ../../../../
>>> dictionary = {"one":"one value", "two":"two value"}
>>> new_dictionary = {"foo":"foo value", "bar":"bar value"}
>>> dictionary.update(new_dictionary)
>>> print(dictionary)
{'one': 'one value', 'two': 'two value', 'foo': 'foo value', 'bar': 'bar value'}
>>> dictionary = {"one":"one value", "two":"two value"}
>>> new_dictionary = {"foo":"foo value", "bar":"bar value"}
>>> dictionary.update({**new_dictionary})
>>> print(dictionary)
class CustomException(Exception):
def __init__(self, extra_context, message):
self.extra_context = extra_context
self.message = message
super().__init__(self.message)
def __str__(self):
return f'Shit going down! {self.message} | extra context: {self.extra_context}'
try:
raise CustomException("extra context", "some message")