Skip to content

Instantly share code, notes, and snippets.

@chrisribe
chrisribe / install_python_apt.sh
Last active October 4, 2024 15:33
Install latest python version from python.org / atp install
#!/bin/bash
# Inspired by: https://linuxcapable.com/install-python-3-12-on-ubuntu-linux/
# Function to get the latest stable Python version
get_latest_stable_python_version() {
# Fetch the HTML content and store it in a variable
HTML_CONTENT=$(curl -s --compressed https://www.python.org/downloads/ | tr -d '\0')
# Check if HTML_CONTENT is empty
@chrisribe
chrisribe / Git alias to update main branch in one step
Last active May 28, 2024 12:47
Alias 'mainup' for Updating and Keeping 'main' Branch Up-to-Date While on Working Branch
# Set up a Git alias called 'mainup' that updates the 'main' branch and brings it up-to-date while staying on the current working branch
# Run the following command to set up the alias:
git config --global alias.mainup '!git rev-parse --abbrev-ref HEAD > .git/CURRENT_BRANCH && git checkout main && git pull && git checkout $(cat .git/CURRENT_BRANCH) && rm .git/CURRENT_BRANCH'
# Now you can update the 'main' branch and bring it up-to-date while staying on your working branch by running the 'mainup' command:
git mainup
@chrisribe
chrisribe / -design-patterns-cheat-sheet.md
Last active June 23, 2023 18:11
A cheat sheet outlining some popular design patterns, their pros and cons, and guidance on when to use them

Here's a cheat sheet outlining some popular design patterns, their pros and cons, and guidance on when to use them:

  1. Singleton Pattern:

    • Pros: Ensures only one instance of a class exists, provides a global point of access.
    • Cons: Can introduce tight coupling and make unit testing difficult.
    • Use when: You need to limit the number of instances of a class, such as for managing shared resources or global configurations.
  2. Factory Pattern:

    • Pros: Provides a centralized place to create objects, encapsulates object creation logic.
  • Cons: Can become complex as the number of product types increases.
//Events to break on.
var aEvents = [
'click',
'touchstart'
];
function breakNow(e) {
console.log(`break now 4 event: ${e.type}`, e);
console.log("STACK is:", stackTrace());
@chrisribe
chrisribe / arrayContains.js
Last active August 12, 2022 19:52
Array contains partial and exact match
var allowedURLs = [
"https://www.google.com",
"https://www.youtube.com/watch?v=mp5WJwT7HW0",
"https://www.youtube.com"
];
function arrayContains(targetArray, stringTofind, exactMatch) {
var matches = targetArray.filter(function (aItem) {
if (exactMatch)
return (stringTofind === aItem);
@chrisribe
chrisribe / SwipeListener.js
Last active January 1, 2022 15:55
Simple Swipe Event Listener
// Swipe listener for mobile touch events
// run in chrome console in mobile mode and swipe at the current page body
function SwipeListener(targetId, fn){
this.startX = 0;
this.startY = 0;
this.swipeEventCb = fn;
this.gestureZone = document.querySelector(targetId);
this.start();
}
@chrisribe
chrisribe / php-tools.php
Last active January 28, 2020 19:58
PHP kill / terminate process by exe name
/**
* Kill windows process if found and older that given time (defaults to now)
* Ref: https://stackoverflow.com/questions/14385122/how-to-kill-a-windows-process-running-longer-than-30-minutes
*/
function killProcessByName($processName, $ifOlderThan = "now"){
//Build datetime formated for "wmic process CreationDate"
//Format: year-month-day-hour-minute-second-microsecond-timezone (in minutes!!!)
$dt = new DateTime($ifOlderThan);
$t = $dt->format('YmdHis.u') . ($dt->format('Z') / 60);