Skip to content

Instantly share code, notes, and snippets.

View chrisgrande's full-sized avatar

Christopher Grande chrisgrande

View GitHub Profile
@chrisgrande
chrisgrande / launch_app_if_not_running.py
Created March 8, 2019 01:30
Check if app is running, if not, launch it
#!/usr/bin/python
from AppKit import NSWorkspace, NSBundle, NSRunningApplication
import sys
# app to look for and launch if not running
app_name = 'OneDrive'
app_bundle_id = 'com.microsoft.OneDrive'
# hide the python rocket ship
class TurbolinksMiddleware(object):
"""
Send the `Turbolinks-Location` header in response to a visit that was redirected,
and Turbolinks will replace the browser's topmost history entry.
"""
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
@chrisgrande
chrisgrande / upgrade.md
Created September 22, 2020 22:46 — forked from zulhfreelancer/upgrade.md
How to upgrade Heroku Postgres database plan?
  1. Assuming you have multiple Heroku apps and Git remote like so:
development https://git.heroku.com/xxx.git (fetch)
development https://git.heroku.com/xxx.git (push)
origin      git@bitbucket.org:xxx/xxx.git  (fetch)
origin      git@bitbucket.org:xxx/xxx.git  (push)
production  https://git.heroku.com/xxx.git (fetch)
production  https://git.heroku.com/xxx.git (push)
staging https://git.heroku.com/xxx.git (fetch)
@chrisgrande
chrisgrande / slugify_controller.html
Last active April 17, 2021 07:45
Generic slugify Stimulus controller. Takes input text and outputs slugified version as you type to another input field.
<div data-controller="slugify">
<input data-slugify-target="input" data-action="input->slugify#inputToOutput" type="text">
<input data-slugify-target="output" type="text">
</div>
#!/usr/local/mxcc/mxcc-python3
import os
from docklib import Dock
from AppKit import NSBundle, NSRunningApplication
from pathlib import Path
import sys
import time
import pwd
#!/usr/bin/env python3
from AppKit import NSWorkspace
def is_alias (path):
uti, err = NSWorkspace.sharedWorkspace().typeOfFile_error_(
os.path.realpath(path), None)
if err:
raise Exception(err)
else:
#!/bin/bash
# Get Policy Paramamter for the Installer UID.
BOMGAR_CODE=$4
if [ -z "$BOMGAR_CODE" ]; then
echo "You must configure the installer UID in the Jamf Policy!"
exit 1
fi
@chrisgrande
chrisgrande / mixins.py
Created March 24, 2023 17:00
Django view mixin to redirect to a named view on 404
from django.http import Http404
from django.urls import reverse
from django.shortcuts import redirect
from django.views.generic.detail import SingleObjectMixin
class RedirectOn404Mixin(SingleObjectMixin):
redirect_url_name = None
def get(self, request, *args, **kwargs):
@chrisgrande
chrisgrande / hover_dns_exporter.py
Created May 3, 2023 01:06
Exports DNS Zone information from your Hover.com account for each domain
import requests
import json
# Username and password
name = 'username'
password = 'password'
# Login to Hover
s = requests.Session()
r = s.post('https://www.hover.com/api/login',