Skip to content

Instantly share code, notes, and snippets.

View hotpaw2's full-sized avatar

Ronald Nicholson hotpaw2

View GitHub Profile
@hotpaw2
hotpaw2 / nsurl.dtask.test1.swift
Created May 6, 2017 22:07
test of command-line Swift for an NSURLSession dataTask
View nsurl.dtask.test1.swift
//
// command-line Swift test of an NSURLSession dataTask
// 2017-May-06 rhn@nicholson.com (hotpaw)
//
// compile and run using:
//
// swiftc nsurl.dtask.test1.swift -o mytest1
// ./mytest1
//
View ble.perip.button.1.bas
100 rem BLE peripheral button service emulation
102 rem for HotPaw Basic 1.7.7 , 2017-12 , by rhn@nicholson.com
104 rem Provides the same button service as a TI SensorTag
106 rem Tap on the iPhone display to send a BLE notification
108 rem Enter any character to exit
110 rem
120 fn btle.init()
130 print "Initializing ..."
140 fn sleep(1) : fn sleep(1)
160 fn btle.name(1,"HotPaw Button Test")
View sensortag.count.2.bas
100 rem SensorTag button press counter
102 rem This program will connect to and count TI SensorTag button presses.
104 rem It can count even in the background or with the iPhone display off.
106 rem Select a Sensor in the List and wait for connection success.
108 rem Tap the display to exit.
110 rem for HotPaw Basic 1.7.7 , rhn@hotpaw.com , 2017-12-08
112 rem
120 fn btle.init()
125 print "Initializing BLE ..."
130 fn sleep(5)
View fft1.bas
rem Some tutorial DSP subroutines for Chipmunk Basic
rem
rem genstab() Generates a sine table for use by the fft() subroutine
rem fft() Implementation of a common in-place DIT FFT algorithm
rem *** genstab(m) - a subroutine to generate sine table of length 2^m ***
rem *** must be called before calling fft() for
rem the first time, and if the length 2^m changes
sub genstab(m)
@hotpaw2
hotpaw2 / udp_receive.swift
Last active February 24, 2018 18:38 — forked from NeoTeo/UDPSendReceive.swift
A minimal implementation of a Posix UDP server in Swift.
View udp_receive.swift
//
// receive packets via UPD in Swift
// Original: https://gist.github.com/NeoTeo/b6195efb779d925fd7b8
// server only converted to Swift 4 2018-02-24 by rhn@nicholson.com
//
// swiftc udp_receive.swift -o udp_receive
//
import Foundation
@hotpaw2
hotpaw2 / discovery.emulator.c
Last active November 6, 2020 02:52
Hermes Lite 2 Discovery emulator
View discovery.emulator.c
// Hermes Lite 2 Protocol 1 Discovery emulator
// emulates the behavior of the FPGA inside an OpenHPSDR radio.
// waits for 1 63-byte broadcast packets on port 1024 ,
// replies with a 60 byte UDP packet
// Version 2020/11/03 (b) rhn@hotpaw.com
//
// #define PI_LINUX
#define REPLY_ENABLE (1)
#define DEFAULT_PORT (1024)
View sieve.c
/* sieve.c */
/* An old small benchmark from Byte Magazine, circa 1983 and 1984, thus suitable for that vintage of computer. */
#include <stdio.h>
#define TIMES (100000L)
static unsigned char f[8192];
int main()
{
View MyURLStreamTask.swift
// MyURLStreamTask.swift
// Demonstrates using an NSURLSessionStreamTask to implement a bidirectional TCP socket connection
//
// by rhn@nicholson.com 2017-03-07
// distribution: BSD 2-clause
//
import Foundation
class MyURLStreamTask {
@hotpaw2
hotpaw2 / RecordAudio.swift
Last active June 18, 2023 04:03
Swift Audio Recording class. Reads buffers of input samples from the microphone using the iOS RemoteIO Audio Unit API
View RecordAudio.swift
//
// RecordAudio.swift
//
// This is a Swift class (updated for Swift 5)
// that uses the iOS RemoteIO Audio Unit
// to record audio input samples,
// (should be instantiated as a singleton object.)
//
// Created by Ronald Nicholson on 10/21/16.
// Copyright © 2017,2019 HotPaw Productions. All rights reserved.
@hotpaw2
hotpaw2 / ToneOutputUnit.swift
Last active October 29, 2023 13:13
Swift 3 Audio class that can play a simple tone on an iOS device
View ToneOutputUnit.swift
//
// ToneOutputUnit.swift
//
// This is a Swift 3 class (which should be instantiated as a singleton object)
// that can play a single tone of arbitrary tone and frequency on iOS devices
// using run-time sinewave synthesis and the Audio Unit v3 API with RemoteIO.
//
// Created by Ronald Nicholson rhn@nicholson.com on 2/20/2016.
// revised 2016-Sep-08 for Swift 3
// http://www.nicholson.com/rhn/