Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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'
@Neradoc
Neradoc / finderbug-cpy.md
Last active June 14, 2023 23:05
Finder bug when openning files with multiple boards connected

First, random bits from discord conversation:

has anyone encountered a situation on macOS (Catalina) where you double click "code.py" on one circuit python drive but it opens the code.py from another ? I often have multiple devices connected, usually with different drive names (CLUE, QTPY, etc). It happens with different apps, or using the open command line, but it does not happen when using the "open" dialog from within the apps.

let's say I have "BLUEREMOTE" (a feather nrf52) and "CIRCUITBLUE" (a CPB), typing open /Volumes/CIRCUITBLUE/code.py actually opens /Volumes/BLUEREMOTE/code.py

@Neradoc Yes. Lately in Finder, only one CIRCUITPY drive out of many shows up. And so it only opens the files from that drive if I'm opening through finder. I've had to go through command line to find them, or go into /Volumes in Finder.

@Neradoc
Neradoc / mcc_pin_mapping_sorted.py
Last active September 13, 2021 17:09
List all the pins in the board and microcontroller modules, all aliases on the same line, microcontroller pin first
import board
import microcontroller
allpins = []
for pin in dir(microcontroller.pin):
if isinstance(getattr(microcontroller.pin, pin), microcontroller.Pin):
pins = []
for alias in dir(board):
if getattr(board, alias) is getattr(microcontroller.pin, pin):
pins.append("board.{}".format(alias))
pins.sort()
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 / board_pin_mapping.py
Last active July 8, 2023 23:20
List all the pins in the board module, all aliases on the same line, sorted by name
import microcontroller,board
for pin in dir(microcontroller.pin):
if isinstance(getattr(microcontroller.pin, pin), microcontroller.Pin):
pins = ["{:28s} ".format("microcontroller.pin."+pin)]
for alias in dir(board):
if getattr(board, alias) is getattr(microcontroller.pin, pin):
pins.append("board.{}".format(alias))
print(" ".join(pins))
import wifi
import socketpool
import ssl
import secrets
import sys
SSL = False
try:
from secrets import secrets