Skip to content

Instantly share code, notes, and snippets.

View samuelkordik's full-sized avatar

Samuel Kordik samuelkordik

View GitHub Profile
@samuelkordik
samuelkordik / readinglist_pinboard.py
Last active February 16, 2023 07:23
Sync Safari Reading List bookmarks to Pinboard
#!/Users/samuelkordik/.pyenv/shims/python
# ReadingListCatcher
# - A script for exporting Safari Reading List items to Markdown and Pinboard
# Originally by Brett Terpstra 2015, <https://brettterpstra.com/2015/01/06/reading-list-catcher/>
# Modifications by Zach Fine made in 2020 to use the original reading list item in the
# posts to pinboard.
# Updated 2021-06-21 by Samuel Kordik to fix errors due to deprecated API in plistlib,
# changes to Pinboard api and Pinboard python lib; added enhanced logging output
# and error handling to work as a cron job or shell script.
# Uses code from <https://gist.github.com/robmathers/5995026>
{
"global": {
"check_for_updates_on_startup": true,
"show_in_menu_bar": true,
"show_profile_name_in_menu_bar": false
},
"profiles": [
{
"complex_modifications": {
"parameters": {
// javascript:(function()%20{window.frames.contentFrame.contentDocument.querySelector(%22%23solution%22).value%20=%20%22Duplicate%20EHR%20records%20have%20been%20removed.%20If%20the%20call%20has%20not%20been%20imported%20from%20CAD%2C%20it%20will%20remain%20in%20that%20import%20list%20for%20several%20days%20before%20automatically%20disappearing.%22;window.frames.contentFrame.contentDocument.querySelector(%22%23status%22).innerHTML%20=%20%27%3Coption%20value=%223%22%20selected=%22%22%3EClosed%3C/option%3E%27;window.frames.contentFrame.contentDocument.querySelector(%22%23status%22).onchange();var%20liElements%20=%20window.frames.contentFrame.contentDocument.querySelectorAll(%27%23td_34_status%20ul.newList%20li%27);for%20(var%20i%20=%200;%20i%20%3C%20liElements.length;%20i%2B%2B)%20{array[i].classList.remove(%27selected%27%2C%27hiLite%27);}window.frames.contentFrame.contentDocument.querySelector(%27%23td_34_status%20li.option_3_option%27).classList.add(%27selected%27%2C%20%27hiLite%27);window.frames.contentFrame
@samuelkordik
samuelkordik / Copy Survey
Last active June 29, 2017 20:08
Bookmarklets
javascript:(function(){
// select active modal's quiz key view
var e = document.querySelectorAll('.modal.fade.in .quiz-key')[0];
// set up object model to save to
var q = {};
q.titl = e.querySelector('h3').innerHTML;
q.contents = [];
var qi_c = 0;
var imagesList = [];
var appC = Application.currentApplication();
appC.includeStandardAdditions = true;
function fetchCurrentTask() {
var output = JSON.parse(appC.doShellScript("curl -v -u xxxx:api_token 'https://www.toggl.com/api/v8/time_entries/current'"));
if (output.data == null) {
return null;
} else {
return output.data;
@samuelkordik
samuelkordik / errors.php
Created June 12, 2015 18:09
errors.php
<?php
/**
* Functions for handling errors
*/
/**
* Logs error message to the app-specific error log.
*
* @package App
@samuelkordik
samuelkordik / togglebluetooth
Created July 8, 2014 15:12
AppleScript to toggle bluetooth on/off
tell application "System Preferences"
reveal pane "com.apple.preferences.Bluetooth"
end tell
tell application "System Events" to tell process "System Preferences"
click button 6 of window 1
end tell
quit application "System Preferences"
@samuelkordik
samuelkordik / paystub.php
Created June 14, 2014 17:41
Simple Paystub Calculator
<?php
/**
*
* Simple Paystub Calculator
* Created by Samuel Kordik
* Copyright 2014 Samuel Kordik
* Licensed under MIT license -- feel free to use modify or extend as you wish, just attribute me in the source code.
*
* This single page form calculates paychecks based on a biweekly pay schedule using 2014 rates.
* It stores rate, # of deductions, pretax and posttax withdrawals in a cookie to simplify
@samuelkordik
samuelkordik / backup.php
Created September 7, 2013 21:26
Simple PHP script to backup MySQL database and email results to me. Adapted from (here)[http://davidwalsh.name/backup-mysql-database-php] with improvements made including using MySQLi, gzipping the backup file (significantly reduces time to email), adding a timing function, and generally making more functional. Note two functions here left fairl…
<?php
/**
* Handles backing up database automatically and emailing it to me.
*/
date_default_timezone_set('America/Chicago'); // necessary in some server environments before using any Date/Time functions.
$timestart = microtime(true);
config(); // sets up constants and configurations for database credentials, error handling, etc. including using local environment specific options.
$filename = backup_tables(DB_HOST, DB_USER, DB_PASS, DB_NAME); // backs up data.
@samuelkordik
samuelkordik / getCSVData
Last active December 20, 2015 04:49
Function to load CSV file from fixtures directory and return it as an array; useful in Unit Testing to get a mock return value for a database operation. Code is totally cribbed from various places online and mashed together for my use.
<?php
public function getCSVData($file) {
$filename = __DIR__."/fixtures/$file.csv";
if (!file_exists($filename)) throw new Exception("CSV file $filename doesn't exist.");
$csv = array_map("str_getcsv", file($filename, FILE_SKIP_EMPTY_LINES));
$keys = array_shift($csv);
foreach ($csv as $i=>$row) {
$csv[$i] = array_combine($keys, $row);
}
return $csv;