Skip to content

Instantly share code, notes, and snippets.

View SerialForBreakfast's full-sized avatar

Joe SerialForBreakfast

View GitHub Profile
anonymous
anonymous / BirdMan
Created February 9, 2014 15:34
package crappyBird;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;
const int trigPin = 4;
const int echoPin = 2;
void setup(){
Serial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop()
@jaredsinclair
jaredsinclair / gist:4de506e108249f39b12d
Created August 22, 2015 16:41
Podfile post-install script for best-practice code signing settings.
post_install do |installer_representation|
installer_representation.pods_project.targets.each do |target|
target.build_configurations.each do |config|
if config.to_s == 'Beta'
config.build_settings['CODE_SIGN_IDENTITY[sdk=iphoneos*]'] = 'iPhone Distribution'
elsif config.to_s == 'Release'
config.build_settings['CODE_SIGN_IDENTITY[sdk=iphoneos*]'] = 'iPhone Distribution'
end
end
end
@NeoTeo
NeoTeo / UDPSendReceive.swift
Last active November 7, 2021 13:32
A minimal implementation of a Posix UDP server and client in Swift.
/// This playground shows how to send and receive packets with low-level Posix UPD protocol API.
import Foundation /// Used for NSUTF8StringEncoding
import XCPlayground
/// Ensure the playground doesn't stop executing at the end of the main thread.
XCPlaygroundPage.currentPage.needsIndefiniteExecution = true
/** Workaround for Swift not having access to the htons, htonl, and other C macros.
This is equivalent to casting the value to the desired bitsize and then
@candostdagdeviren
candostdagdeviren / .swiftlint.yml
Last active July 6, 2024 12:11
Sample SwiftLint file to apply best practices
disabled_rules: # rule identifiers to exclude from running
- variable_name
- nesting
- function_parameter_count
opt_in_rules: # some rules are only opt-in
- control_statement
- empty_count
- trailing_newline
- colon
- comma
@ruuda
ruuda / ledwall.glsl
Last active December 19, 2019 00:23
LED wall shader
// Simulates n colored point lights (LEDs) shining at a wall from a distance wd.
// Wall distance; increase for more fuzzy lights,
// decrease for sharper point lights.
float wd = 0.15f;
const int nLights = 4;
const vec3 lights[nLights] = vec3[](
vec3(1.0f, 0.0f, 0.0f),
vec3(0.0f, 1.0f, 0.0f),
@Sajjon
Sajjon / BaseViewModel.swift
Created November 26, 2018 13:48
Medium article: SLC part 1 - BaseViewModel
import RxSwift
import RxCocoa
class BaseViewModel<NavigationStep, FromView, Output>: ViewModelType {
let bag = DisposeBag()
// Small type wrapping a RxSwift PublishSubject, that we notify about navigation, passing
// a contextual `NavigationStep` which typically is an enum, modelling all possible
// outgoing navigation steps we can take from this scene.
let navigator = Stepper<NavigationStep>()
@SerialForBreakfast
SerialForBreakfast / MaxProfitQuestion.swift
Created May 19, 2019 06:27
Find the largest margin to place a buy and sell order over a day.
import UIKit
let stockPrices:[Int] = [10, 7, 5, 8, 11, 9]
func getMaxProfit(from: [Int]) -> Int {
var bestProfit: Int = 0
var newSell: Int = 0
var newBuy: Int = Int.max
var newSpread: Int = 0
@lamprosg
lamprosg / Caching.swift
Last active January 1, 2020 02:41
(iOS) Caching
// To be able to use strings as caching keys, we have to use
// NSString here, since NSCache is only compatible with keys
// that are subclasses of NSObject:
let cache = NSCache<NSString, MyClass>()
//Problem:
//can only store class instances, and it’s only compatible with NSObject-based keys
//NSCache simple use here:
//https://www.hackingwithswift.com/example-code/system/how-to-cache-data-using-nscache