Skip to content

Instantly share code, notes, and snippets.

@Neradoc
Neradoc / log_with_emojis_and_types2.swift
Created April 15, 2016 05:22
A variation on logging with emojis, using an empty enum to namespace static funcs
// a variation of https://gist.github.com/Neradoc/86b3468a1612f8e1d57db20ab2fab5ae
// uses an empty enum as namespace for static functions
// otherwise it's pretty much the same
enum Log {
private static func __log<T>(type:String,_ input:T) {
//#if DEBUG
print(type,input)
//#endif
@Neradoc
Neradoc / log_with_emojis_and_types.swift
Last active April 15, 2016 05:23
Example code for emoji-fueled logs with type safety
// A logging function that uses emojis to make the output prettier
// - one clear way to specify the type of display we want
// - provide type safety for the printed parameter
// - no weird operator syntax ;-)
// Inspired by "Swift: Pretty in print()" by Andyy Hope
// part 1: https://medium.com/p/64832bb7fafa/
// part 2: https://medium.com/p/640cea920653/
// Note: Ideally you would give the object to print first, so the completion
@Neradoc
Neradoc / CircuitPlaygroundPhoneLight.ino
Last active September 17, 2016 04:45
Phone light with Circuit Playground as a Neopixel ring
#include <Adafruit_CircuitPlayground.h>
#include <Wire.h>
#include <SPI.h>
#define BLINKY 13
// Threshold for a capacitive touch (higher = less sensitive).
#define CAP_THRESHOLD 100
// Number of samples to take for a capacitive touch read.
#define CAP_SAMPLES 40
@Neradoc
Neradoc / neopixelTestWithArgs.py
Last active September 18, 2016 13:54
Micropython test for neopixels with arguments using "ampy run".
import time,sys
from machine import Pin
from neopixel import NeoPixel
color = [0,64,64]
if len(sys.argv) >= 4:
try:
col = [int(sys.argv[1]),int(sys.argv[2]),int(sys.argv[3])]
color = col
except:
@Neradoc
Neradoc / arduinoInstall.py
Last active January 10, 2021 09:59
Arduino sketch installer from the command line (mac version)
#!/usr/bin/env python3
import argparse, os, re, subprocess, glob, datetime, sys, shutil
import usb
import serial.tools.list_ports
tmpFiles= "/tmp/arduinotmp"
logFile = "/Users/spyro/Developement/ArduinoLib/ArduinoInstall.log"
arduinoCommand = ['arduino-cli',"compile"]
RED = '\033[91m'
"""
NOTE: requires the usual secrets.py file
The test
- connects to the server
- sends headers to switch to websockets mode
- reads the headers that the server sends back
Note: the code doesn't do anything else with the connection,
it will hang or disconnect, but it should receive the headers first.
import wifi
import ssl
import socketpool
import adafruit_requests
from secrets import secrets
print("WIFI: Connecting")
#wifi.radio.start_scanning_networks()
wifi.radio.connect(secrets['ssid'],secrets['password'])
#wifi.radio.stop_scanning_networks()
@Neradoc
Neradoc / oled_temperature.py
Created March 3, 2021 16:15
Display a temperature sensor on an I2C OLED REPL with the QT PY Haxpress
import time
import board
print("I2C")
i2c = board.I2C()
while not i2c.try_lock():
i2c.unlock()
#i2c.unlock()
try:
scan = i2c.scan()
@Neradoc
Neradoc / code_openlcd_temp.py
Last active March 3, 2021 16:25
Display temperature on a Sparkfun SerLCD with a minimal driver
import time
import board
DISPLAY_ADDRESS1 = 0x72
i2c = board.I2C()
# from sparkfun_serlcd import Sparkfun_SerLCD_I2C
# lcd = Sparkfun_SerLCD_I2C(i2c,DISPLAY_ADDRESS1)
import openlcd_mini
# The MIT License (MIT)
#
# Copyright (c) 2017 Dan Halbert
#
# 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: