Skip to content

Instantly share code, notes, and snippets.

View eahrold's full-sized avatar

Eldon Ahrold eahrold

View GitHub Profile
@eahrold
eahrold / HttpSessionResolver
Created May 9, 2022 01:56
A micronaut HttpSessionResolver
package com.example;
import io.micronaut.http.HttpRequest;
import io.micronaut.http.context.ServerRequestContext;
import io.micronaut.session.Session;
import io.micronaut.session.SessionStore;
import io.micronaut.session.http.SessionForRequest;
import jakarta.inject.Singleton;
import java.util.Optional;
@eahrold
eahrold / closeapp.py
Created January 14, 2014 18:00
close a running application with python and NSWorkspace
#!/usr/bin/python
from AppKit import NSWorkspace
def closeRunningApplication(bundle_id):
ws = NSWorkspace.sharedWorkspace()
runningApps = ws.runningApplications()
for i in runningApps:
if i.bundleIdentifier() == bundle_id:
i.terminate()
@eahrold
eahrold / OSXMounter.py
Last active November 21, 2020 16:11 — forked from pudquick/mount_shares.py
Programmatically mount shares in OS X via python without the need for AppleScript
import os
import objc, CoreFoundation
from ctypes import c_void_p, pointer, cast
# The only reason I'm doing this the XML way is because I don't have a better way (yet)
# for correcting a function signature -after- it's already been imported.
# The problem is the last argument is a pointer to a CFArrayRef, which works out to a
# pointer to a pointer to a CFArray. pyobjc doesn't handle that much abstraction, so I created
# a custom opaque type 'CFArrayRefRef' and manually handle the conversion to/from pointer.
@eahrold
eahrold / ProcessPipe.swift
Last active October 24, 2020 17:12
pipe Process (NSTask) in swift
//
// ProcessPipe.swift
//
// Created by Eldon on 8/10/18.
// Copyright © 2018 Big Club Digital. All rights reserved.
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTIO
@eahrold
eahrold / CFPreference Domains
Last active June 22, 2020 17:50
CFPreference Domains
Precedence is:
/Library/Managed Preferences/ -- MCX
~/Library/Preferences -- User Home
/Library/Preferences/ -- Shared
~/Library/Preferences/com.app.plist = kCFPreferencesCurrentUser
kCFPreferencesCurrentApplication
kCFPreferencesAnyHost
~/Library/Preferences/.GlobalPreferences = kCFPreferencesCurrentUser
@eahrold
eahrold / launchatlogin.py
Last active June 22, 2020 16:41
Launch App At Login via LaunchAgent py (for munki)
#!/usr/bin/python
import subprocess
import plistlib
from os import seteuid
from ServiceManagement import *
from SystemConfiguration import SCDynamicStoreCopyConsoleUser
installdir = 'Applications'
@eahrold
eahrold / cecho
Created January 8, 2014 23:12
Color Read / Color Echo in bash
#!/bin/bash
cread(){
case "$1" in
red|alert) local COLOR=$(printf "\\e[1;31m");;
green|attention) local COLOR=$(printf "\\e[1;32m");;
yellow|warn) local COLOR=$(printf "\\e[1;33m");;
blue|question) local COLOR=$(printf "\\e[1;34m");;
purple|info) local COLOR=$(printf "\\e[1;35m");;
cyan|notice) local COLOR=$(printf "\\e[1;36m");;
@eahrold
eahrold / chunkablePromises.js
Last active March 30, 2020 19:28
Chunkable Promises
const _ = require('lodash')
/**
* Async Waiting utility
* @param {Number} wait Number of MS to wait
* @return {Promise} A promise to await
*/
const waiter = async function(wait = 0) {
return new Promise((resolve) => {
if (wait <= 0) {
@eahrold
eahrold / HelperTool_CodeSign_RunScript.py
Created February 24, 2014 22:45
Automatically get the proper Values in a PriviledgedHelperTool's Info.plist / LaunchD
#!/usr/bin/python
''' Place this script at the root of the project directory
and enter this for a Run Script during build phase of the helper app
${PROJECT_DIR}"/HelperTool_CodeSign_RunScript.py
put the run script right after Target Dependencies
What this script does is write the SMPrivilegedExecutables dictionary
[2016-02-16 15:43:05] local.ERROR: Symfony\Component\Debug\Exception\FatalThrowableError: Type error: Argument 1 passed to Illuminate\Routing\Middleware\ThrottleRequests::addHeaders() must be an instance of Illuminate\Http\Response, instance of Illuminate\Http\JsonResponse given, called in /home/vagrant/Code/MyCatsProject/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php on line 52 in /home/vagrant/Code/MyCatsProject/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php:94
Stack trace:
#0 /home/vagrant/Code/MyCatsProject/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php(52): Illuminate\Routing\Middleware\ThrottleRequests->addHeaders(Object(Illuminate\Http\JsonResponse), '60', 59)
#1 [internal function]: Illuminate\Routing\Middleware\ThrottleRequests->handle(Object(Illuminate\Http\Request), Object(Closure), '60', '1')
#2 /home/vagrant/Code/MyCatsProject/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_