Skip to content

Instantly share code, notes, and snippets.

View genedelisa's full-sized avatar
💭
Feeding the cats

Gene De Lisa genedelisa

💭
Feeding the cats
View GitHub Profile
@genedelisa
genedelisa / Makefile
Last active June 22, 2021 12:31
Simple Makefile for command line Swift
# Simple Makefile for command line Swift projects
# Gene De Lisa
PROG = example
SRC = src/*.swift
INSTALL_DIR = ./bin
SWIFTC=xcrun --sdk macosx swiftc
# this is a hack right now just to compile
@genedelisa
genedelisa / catimgreddit.zsh
Last active September 7, 2020 03:41
zsh script to grab cat images from Reddit. One random, All from a subreddit, optionally download them, and optionally view them via QuickLook.
#!/usr/bin/env zsh
# -*- mode: shell-script -*-
#
# Time-stamp: "Last Modified 2020-05-22 14:43:23 by Gene De Lisa, genedelisa"
#
# File: ~/dotfiles/.zsh/scripts/
# Gene De Lisa
# gene@rockhoppertech.com
# http://rockhoppertech.com/blog/
@genedelisa
genedelisa / keybase.md
Created November 12, 2019 08:55
keybase verification

Keybase proof

I hereby claim:

  • I am genedelisa on github.
  • I am genedelisa (https://keybase.io/genedelisa) on keybase.
  • I have a public key ASAHwfTYYwBrMBqbQnBjbRfExg-lU_I-m87yjiYjzKyfdwo

To claim this, I am signing this object:

@genedelisa
genedelisa / tasks.json
Created June 11, 2019 02:33
VS code tasks for compiling C++
{
// https://code.visualstudio.com/docs/editor/tasks
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
// build and run the current cpp file you're editing.
"label": "Build with Clang C++17",
@genedelisa
genedelisa / Toolbar.swift
Last active November 12, 2016 11:46
UIToolbar with bar buttons using a custom font using Swift 3
if let nav = navigationController {
nav.setToolbarHidden(false, animated: false)
// doesn't really set the button's tint
UIToolbar.appearance().tintColor = UIColor.black
// instead of setting the text color of each bar button
UIBarButtonItem.appearance().tintColor = UIColor.black
@genedelisa
genedelisa / Toolbar.swift
Last active November 12, 2016 11:46
Create buttons in a navigationController's UIToolbar using Swift 3
if let nav = navigationController {
nav.setToolbarHidden(false, animated: false)
// doesn't really set the button's tint
UIToolbar.appearance().tintColor = UIColor.black
// instead of setting the text color of each bar button
UIBarButtonItem.appearance().tintColor = UIColor.black
@genedelisa
genedelisa / Autolayout.swift
Last active November 12, 2016 11:47
Programmatic autolayout constraints
// the frame size doesn't matter; autolayout will change it
var aButton = UIButton(frame: CGRect(x: 0, y: 0, width: 200, height: 200))
aButton.titleLabel?.text = "HEY"
aButton.opaque = true
aButton.backgroundColor = UIColor.yellow
view.addSubview(aButton)
aButton.translatesAutoresizingMaskIntoConstraints = false
let margins = view.layoutMarginsGuide
@genedelisa
genedelisa / collectionViewScroll
Last active November 22, 2023 22:22
UICollectionView scroll to make section header visible
/**
Scroll to make the the given section header visible.
The function scrollToItemAtIndexPath will scroll to the item and hide the section header.
Swift 3.
*/
func scrollToSection(_ section:Int) {
if let cv = self.collectionView {
let indexPath = IndexPath(item: 1, section: section)
if let attributes = cv.layoutAttributesForSupplementaryElement(ofKind: UICollectionElementKindSectionHeader, at: indexPath) {
@genedelisa
genedelisa / StringLiteralConvertibleExample
Created February 2, 2015 10:57
Swift StringLiteralConvertible
public class Foo : StringLiteralConvertible {
var num:Int = 0
required public init(stringLiteral value: StringLiteralType) {
self.num = value.toInt()!
// of course you can do something more complicated by parsing the value.
}
public typealias UnicodeScalarLiteralType = StringLiteralType
@genedelisa
genedelisa / Loop.swift
Created November 11, 2014 14:13
Looping an iOS/OSX AudioToolbox MusicTrack in Swift
func loopTrack(musicTrack:MusicTrack) {
var trackLength = getTrackLength(musicTrack)
println("track length is \(trackLength)")
setTrackLoopDuration(musicTrack, duration: trackLength)
}
func getTrackLength(musicTrack:MusicTrack) -> MusicTimeStamp {
//The time of the last music event in a music track, plus time required for note fade-outs and so on.