Skip to content

Instantly share code, notes, and snippets.

View lsloan's full-sized avatar

Mr. Lance E Sloan «UMich» lsloan

  • Teaching and Learning (@tl-its-umich-edu) at University of Michigan: Information and Technology Services
  • Ann Arbor, Michigan, USA
  • 06:11 (UTC -04:00)
  • X @lsloan_umich
View GitHub Profile

Mathematical Summations in Python

Problem

I saw a video that claimed the following mathematical summation…

$$\sum_{\substack{i=0 \\ i\neq 4}}^{n} i$$
@lsloan
lsloan / BetterEnum.php
Last active April 12, 2024 01:02
BetterEnum.php: A pure-PHP alternative to SplEnum, although only a 99% compatible replacement for it.
<?php
/**
* Class BetterEnum
*
* A pure-PHP alternative to SplEnum, although only a 99% compatible replacement for it.
*
* See: http://php.net/manual/en/class.splenum.php
*
* To declare an enum class, subclass BetterEnum and define the names and values as constants.
@lsloan
lsloan / Copy Bitbucket repo to GitHub.md
Last active March 20, 2024 15:41 — forked from mandiwise/Update remote repo
Copy Bitbucket repo to GitHub

Copy Bitbucket repo to GitHub

Whenever possible, use GH's "Import repository" feature.

The import feature doesn't always work, though. In my experience, I tried to import a repo and it failed with a generic message. I had to contact GH support to ask for help. They told me my repo had a large file (>100MB), which couldn't be added to GH directly. I had to either remove the file or store it in GH LFS. In this case, one of the CLI methods below are needed:

CLI: Copy the master branch only (OK)

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@lsloan
lsloan / periodFormatIso8601.py
Last active November 10, 2023 18:43
Two functions for creating a timestamp from a number of seconds. One from StackOverflow and mine. I thought I could do better.
def time_format(seconds: int) -> str:
"""
From: https://stackoverflow.com/a/68321739/543738
"""
if seconds is not None:
seconds = int(seconds)
d = seconds // (3600 * 24)
h = seconds // 3600 % 24
m = seconds % 3600 // 60
@lsloan
lsloan / caliper_custom_action_example.php
Last active September 13, 2023 14:30
Caliper: An example of using caliper-php to send an event with custom action and context.
<?php
require_once 'vendor/autoload.php';
use IMSGlobal\Caliper\actions\Action;
use IMSGlobal\Caliper\Client;
use IMSGlobal\Caliper\context\Context;
use IMSGlobal\Caliper\entities\agent\Person;
use IMSGlobal\Caliper\entities\agent\SoftwareApplication;
use IMSGlobal\Caliper\entities\media\MediaLocation;
use IMSGlobal\Caliper\entities\media\VideoObject;
@lsloan
lsloan / Postman current timestamp for UTC as ISO 8601.md
Last active September 4, 2023 11:44
Postman current timestamp for UTC as ISO 8601

I wanted to know: How can I get the current timestamp for UTC in ISO 8601 format to appear in the body data of a Postman request?

After reading some of the Postman documentation and online comments, this is the solution (using Postman v5.0.1 for Chrome 58.0.3029.110 on macOS 10.12.5) I used:

  1. In the Builder, while editing a request, click the "Pre-request Script" heading below the URL field.

  2. In the editor field that appears, enter this single line of JavaScript:

    postman.setGlobalVariable('timestampUtcIso8601', (new Date()).toISOString());
@lsloan
lsloan / decrypt_dbeaver.py
Created August 11, 2023 02:44 — forked from felipou/decrypt_dbeaver.py
DBeaver password decryption script
# https://stackoverflow.com/questions/39928401/recover-db-password-stored-in-my-dbeaver-connection
import sys
import base64
print(sys.argv[1])
PASSWORD_ENCRYPTION_KEY = b"sdf@!#$verf^wv%6Fwe%$$#FFGwfsdefwfe135s$^H)dg"
@lsloan
lsloan / decrypt_dbeaver.py
Created August 11, 2023 02:43 — forked from felipou/decrypt_dbeaver.py
DBeaver password decryption script - for newer versions of DBeaver
# https://stackoverflow.com/questions/39928401/recover-db-password-stored-in-my-dbeaver-connection
# requires pycryptodome lib (pip install pycryptodome)
import sys
import base64
import os
import json
from Crypto.Cipher import AES
@lsloan
lsloan / umich-udp-bigquery-to-pandas-dataframe.ipynb
Last active July 19, 2023 02:46
umich-udp-bigquery-to-pandas-dataframe.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.