Skip to content

Instantly share code, notes, and snippets.

View joeyhoer's full-sized avatar

Joey Hoer joeyhoer

View GitHub Profile
@drudge
drudge / ip.star.py
Last active December 29, 2021 04:50
Public IP Address Applet for Tidbyt
# Public IP Tidbyt App
# MIT License
# by Nicholas Penree, Dec 28 2021
load("render.star", "render")
load("http.star", "http")
load("cache.star", "cache")
IPIFY_JSON_URL = "https://api.ipify.org/?format=json"
MOCK = False
@drewkerr
drewkerr / get-focus-mode.js
Last active April 23, 2024 12:34
Read the current Focus mode on macOS Monterey (12.0+) using JavaScript for Automation (JXA)
const app = Application.currentApplication()
app.includeStandardAdditions = true
function getJSON(path) {
const fullPath = path.replace(/^~/, app.pathTo('home folder'))
const contents = app.read(fullPath)
return JSON.parse(contents)
}
function run() {
@siraben
siraben / autocollect.sh
Last active February 9, 2021 18:59
macOS script to collect and dedup MAC addresses from a network
#!/bin/bash
# SPDX-License-Identifier: MIT
# SPDX-FileCopyrightText: 2018 Ben Siraphob <bensiraphob@gmail.com>
command -v gshuf >/dev/null 2>&1 || { echo >&2 "gshuf is required but is not installed. Run \"brew install coreutils\"."; control_c; }
command -v spoof-mac >/dev/null 2>&1 || { echo >&2 "spoof-mac is required but is not installed. Run \"brew install spoof-mac\"."; control_c; }
# Colors
RED='\033[0;31m'
NC='\033[0m'
@tylerchilds
tylerchilds / createScrollManager.js
Created June 4, 2019 02:02
Use requestAnimationFrame to handle scrolling smoothly
const createScrollManager = function() {
let callbacks = [];
let scrollPosition = -1;
let animatedKilled = false;
const animate = () => {
requestAnimationFrame(onScroll);
}
function onScroll(){
@vraravam
vraravam / osx-defaults.sh
Last active March 17, 2024 01:21
OSX Defaults to setup a brand new machine
#!/usr/bin/env bash
# TODO: Need to figure out the settings for the following:
# 1) Dock: Items with order (not capturing binary data - since that is dependent on installed apps)
# 2) Security & Privacy Preferences: Full Disk Access, Camera, Microphone
# 3) Login items for my user (i.e. apps started when I login)
# 4) Retina displays scaling
# 5) Finder sidebar with order
##
@jgrahamc
jgrahamc / pwnd.js
Created February 24, 2018 16:36
Cloudflare Workers that adds an "Cf-Password-Pwnd" header to a POST request indicating whether the 'password' field appears in Troy Hunt's database of pwned passwords.
addEventListener('fetch', event => {
event.respondWith(fetchAndCheckPassword(event.request))
})
async function fetchAndCheckPassword(req) {
if (req.method == "POST") {
try {
const post = await req.formData();
const pwd = post.get('password')
const enc = new TextEncoder("utf-8").encode(pwd)
DISCOUNTS_BY_QUANTITY = {
4 => 20,
3 => 15,
2 => 10
}
discunted_count = 0
Input.cart.line_items.each do |line_item|
if line_item.variant.product.tags.include?('DiscountTag')
@emilyemoss
emilyemoss / spend_$x_get_y%_off.rb
Created November 26, 2017 23:46
Shopify Script - Spend $X Get Y% Off
total = Input.cart.subtotal_price_was
# spend more than $150 earns 25% off
if total > Money.new(cents:100) * 150
discount = 0.25
message = "25% Off"
# spend between $50 and $150 earns 20% off
elsif total > Money.new(cents:100) * 50
discount = 0.20
message = "20% Off"
@ryangreenberg
ryangreenberg / dnd.sh
Created October 24, 2017 22:40
Do Not Disturb
#!/bin/bash
set -eou pipefail
# From https://heyfocus.com/enabling-do-not-disturb-mode and
# https://apple.stackexchange.com/questions/145487
if [[ $(defaults -currentHost read ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturb) -eq 0 ]]; then
defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturb -boolean true
defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturbDate -date "`date -u +\"%Y-%m-%d %H:%M:%S +000\"`"
@thebostik
thebostik / dynamic_quality.py
Created May 30, 2017 22:02
Python Dynamic Image Quality Example
import cStringIO
import PIL.Image
from ssim import compute_ssim
def get_ssim_at_quality(photo, quality):
"""Return the ssim for this JPEG image saved at the specified quality"""
ssim_photo = cStringIO.StringIO()
# optimize is omitted here as it doesn't affect
# quality but requires additional memory and cpu