Skip to content

Instantly share code, notes, and snippets.

View atchoo78's full-sized avatar

Andreas atchoo78

View GitHub Profile
@atchoo78
atchoo78 / CLI_open_file_passed_as_argument.swift
Last active December 29, 2023 14:32
Open file name in CLI app passed as -input argument in Swift 5.x
if(CommandLine.arguments.count >= 1) {
for argument in CommandLine.arguments {
if argument.contains("-input") {
let fileInput = CommandLine.arguments.firstIndex(of: "-input")
let fileName = CommandLine.arguments[fileInput! + 1]
// print(fileName)
// do something with fileName here
}
}
@atchoo78
atchoo78 / gatekeeper.zsh
Created July 14, 2023 14:11
Turn "Allow apps from anywhere" (Gatekeeper) option in macOS On or Off
gatekeeper() {
if [ "$1" == "off" ]
then
sudo spctl --master-disable
elif [ "$1" == "on" ]
then
sudo spctl --master-enable
else
sudo spctl --master-enable
fi
@atchoo78
atchoo78 / writehex
Last active February 20, 2023 19:36
writehex - Converts hexadecimal data to ASCII text or pipe it to a file (useful for creating valid System Exclusive MIDI message files). Usage: "./writehex 6964 6b66 6120 6964 6471 6420 6964 7370 6973 706f 7064" or "./writehex F0 00 20 6B 7F 42 02 00 40 52 00 F7>sysex.syx"
#!/usr/bin/env bash
while [ "$1" ]; do
for ((i=0; i<${#1}; i+=2))
do
printf "\x${1:i:2}";
done;
shift;
done
@atchoo78
atchoo78 / dec2hex
Last active June 9, 2022 06:08
System Exclusive file creator
#!/bin/bash
while [ "$1" ]; do
printf "%X " $1
shift;
done
@atchoo78
atchoo78 / lifxScenes.py
Created August 17, 2020 19:35
LIFX Cloud Scenes CLI - Python 3
#!/usr/bin/env python3
# Get API key/token: https://cloud.lifx.com/settings
# PIFX python library: https://github.com/cydrobolt/pifx
from pifx import PIFX
import pifx
import sys
import subprocess
API_KEY = '<PASTE API TOKEN HERE>'
@atchoo78
atchoo78 / RPi_I2C_driver.py
Last active June 29, 2020 16:23 — forked from DenisFromHR/RPi_I2C_driver.py
RaspberryPi I2C LCD Python stuff
# -*- coding: utf-8 -*-
"""
Compiled, mashed and generally mutilated 2014-2015 by Denis Pleic
Made available under GNU GENERAL PUBLIC LICENSE
# Modified Python I2C library for Raspberry Pi
# as found on http://www.recantha.co.uk/blog/?p=4849
# Joined existing 'i2c_lib.py' and 'lcddriver.py' into a single library
# added bits and pieces from various sources
# By DenisFromHR (Denis Pleic)
# 2015-02-10, ver 0.1
@atchoo78
atchoo78 / Example_sensor_data.json
Last active June 26, 2020 19:42
HTTP server on Raspberry Pi providing data from 5 different temperature & humidity sensors. Run "pip3 install -r requirements.txt" first.
[
{
"id": 1,
"name": "DS18B20",
"model": "ds18b20",
"battery": 254,
"deviceType": "0000000D-0001-1000-2005-ACCA54000000",
"uuid": "0000000D-0001-1000-2005-ACCA54000000",
"data": [
{
@atchoo78
atchoo78 / Arduino_Uno_LCD-I2c_test.ino
Last active June 5, 2020 14:24
LiquidCrystal I2C - LCD display test on Arduino Uno
// Note: I recommend connecting SCL and SDA from the LCD to Analog 4 & 5 on the Uno.
// You can also use the SCL and SDA ports (near the USB).
// In general: 16 chars, 2 or 4 lines of text: 0x27
// 20 chars, 4 lines of text: 0x3F
// But remember that most of these i2c adapters are addressable
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
@atchoo78
atchoo78 / Arduino_Yun_LCD_I2C-test.ino
Last active June 5, 2020 14:13
LiquidCrystal I2C - LCD display on Arduino Yún
// Note: Connect SCL and SDA from the LCD to SCL & SDA on the Yun (closest to the ethernet port).
// You can also use digital 2 and 3, but I won't recommend it if you want a reliable serial port connection.
// In general: 16 chars, 2 or 4 lines of text: 0x27
// 20 chars, 4 lines of text: 0x3F
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
@atchoo78
atchoo78 / ledAlert.py
Last active December 16, 2017 09:42
Display current iTunes Track on LED display (max7219 or compatible Dot Matrix LED) connected to Raspberry PI/Arduino.
# -*- coding: utf-8 -*-
#!/usr/bin/env python
# server side script for Raspberry PI
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
import re
import argparse
import time
# Luma.LED_Matrix drivers & library is © 2017 Richard Hull