Skip to content

Instantly share code, notes, and snippets.

@programmarchy
programmarchy / gist:c9d02e22d58bfab3f8bb
Created March 25, 2015 15:45
BluetoothLowEnergy.cpp
// BluetoothLowEnergy.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#pragma warning (disable: 4068)
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
@programmarchy
programmarchy / repeat.c
Last active August 29, 2015 14:21
flow control test
#include <asf.h>
#include <avr/io.h>
#include <avr/wdt.h>
#include <stdint.h>
#define PIN_SET_OUTPUT(ddr, id) ddr |= _BV(id)
#define PIN_SET_INPUT(ddr, id) ddr &= ~_BV(id)
#define PIN_SET_HIGH(port, id) port |= _BV(id)
#define PIN_SET_LOW(port, id) port &= ~_BV(id)
#define PIN_IS_HIGH(pins, id) bit_is_set(pins, id)
@programmarchy
programmarchy / high_water_mark.c
Last active August 29, 2015 14:22
flow control test
#include <asf.h>
#include <avr/io.h>
#include <avr/wdt.h>
#include <stdint.h>
#define PIN_SET_OUTPUT(ddr, id) ddr |= _BV(id)
#define PIN_SET_INPUT(ddr, id) ddr &= ~_BV(id)
#define PIN_SET_HIGH(port, id) port |= _BV(id)
#define PIN_SET_LOW(port, id) port &= ~_BV(id)
#define PIN_IS_HIGH(pins, id) bit_is_set(pins, id)
@programmarchy
programmarchy / choose.js
Last active August 29, 2015 14:25
choices choices choices
function choices(n) {
var map = {}
var rand = function (n) {
return Math.floor(n * Math.random())
}
var stride = (n / 2)
var i = rand(n)
var max = 0
@programmarchy
programmarchy / ember_auth.html
Created July 15, 2016 00:39
Extracts ember auth info from localStorage
<pre id="credentials"></pre>
<button onClick="javascript:sendRequest()">Send Request</button>
<script>
function getEmberSessionCredentials() {
var data = localStorage['ember_simple_auth:session']
if (!data) { return null }
var session = JSON.parse(data)
if (!session) { return null }
@programmarchy
programmarchy / SirenProtocol.swift
Created July 16, 2016 18:15
The Siren specification in Swift protocols
// Siren: a hypermedia specification for representing entities
// https://github.com/kevinswiber/siren
protocol SirenRoot: SirenEntity {}
protocol SirenEntity {
var classNames: [String]? { get }
var properties: [String: AnyObject]? { get }
var entities: [SirenSubEntityType]? { get }
var links: [SirenLink]? { get }
@programmarchy
programmarchy / build-app-icon.sh
Last active May 12, 2020 10:11
Given a high resolution icon image, use imagemagick to scale down to all iOS app icon dimensions
APP_NAME="YOUR_APP_NAME_HERE"
SRC=./Design/AppIcon.png
DST=./$APP_NAME/Assets.xcassets/AppIcon.appiconset
convert $SRC -resize 1024x1024 "$DST/AppIcon1024x1024.png"
convert $SRC -resize 2048x2048 "$DST/AppIcon2048x2048.png"
convert $SRC -resize 29x29 "$DST/AppIcon29x29.png"
convert $SRC -resize 58x58 "$DST/AppIcon29x29@2x.png"
convert $SRC -resize 87x87 "$DST/AppIcon29x29@3x.png"
convert $SRC -resize 80x80 "$DST/AppIcon40x40@2x.png"
@programmarchy
programmarchy / TemplateImageButton.swift
Created April 27, 2017 22:59
View templated images in Interface Builder
import UIKit
@IBDesignable
class TemplateImageButton: UIButton {
#if TARGET_INTERFACE_BUILDER
let templateImageView = UIImageView()
override init(frame: CGRect) {
@programmarchy
programmarchy / Fastfile
Created September 14, 2018 20:21
A Fastlane action that publishes a Pact contract to a Pact broker. See https://pact.io for more details.
# Example Fastfile using the `publish_pact_to_broker` action.
#
# NOTE: Since Fastlane uses dotenv, create a `.env` file in the fastlane
# directory to set `PACT_BROKER_USERNAME` and `PACT_BROKER_PASSWORD` and
# keep it secret by adding it to .gitignore.
default_platform(:ios)
xcodeproj = "MyProject.xcodeproj"
slack_url = "https://hooks.slack.com/services/MY/SLACK/WEBHOOK"
@programmarchy
programmarchy / BusyController.swift
Created November 15, 2018 06:50
A simple drop in controller for making a UIView look busy
import UIKit
class BusyController<V: UIView> {
let view: V
var busyView: UIView? = nil
var busyText: String = "Loading...".localized()
init(view: V) {