Skip to content

Instantly share code, notes, and snippets.

@tempire
tempire / take_screenshot.swift
Created August 5, 2015 07:34
Take raw screenshot on ios with swift
func takeScreenshot(view: UIView) -> UIImageView {
UIGraphicsBeginImageContext(view.frame.size)
view.layer.renderInContext(UIGraphicsGetCurrentContext())
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil)
return UIImageView(image: image)
}
import requests
def segment_image(image_path, api_key):
with open(image_path, 'rb') as image_file:
response = requests.post(
'https://api.deepai.org/api/deepmask',
files={'image': image_file},
headers={'api-key': api_key}
)
if response.status_code == 200:
@tempire
tempire / ble.swift
Last active February 24, 2023 12:35
bluetooth LE advertise/scan
//
// Check.swift
// Points
//
// Created by Glen Hinkle on 10/2/16.
// Copyright © 2016 Zombie Dolphin. All rights reserved.
//
import Foundation
import CoreBluetooth
@tempire
tempire / mojojs.sh
Created September 6, 2022 18:53
Hot reloading of mojojs typescript daemon
npx tsc-watch --onsuccess "node lib/index.js server"
@tempire
tempire / client_certificate.swift
Last active September 1, 2022 09:41
WKWebView with client certificate
//
// ViewController.swift
// CertificateRequest
//
// Created by Glen Hinkle on 3/4/19.
// Copyright © 2019 Zombie Dolphin LLC. All rights reserved.
//
// Works with iOS 12
//
@tempire
tempire / swift_draw_image_on_pdf.swift
Created April 25, 2015 09:24
swift draw image on pdf
func drawOnPDF(path: String) {
// Get existing Pdf reference
let pdf = CGPDFDocumentCreateWithURL(NSURL(fileURLWithPath: path))
// Get page count of pdf, so we can loop through pages and draw them accordingly
let pageCount = CGPDFDocumentGetNumberOfPages(pdf);
// Write to file
UIGraphicsBeginPDFContextToFile(path, CGRectZero, nil)
@tempire
tempire / Kraihlight.css
Created July 18, 2012 02:57
limechat theme
html {
font-family: "Consolas";
font-size: 11pt;
background-color: #1A1A1A;
color: #F9F9F9;
padding: 0;
margin: 0;
}
body {
@tempire
tempire / array_modification.swift
Last active December 1, 2020 06:18
swift array modification in loop
// FAILURE
var array = [["name": "glen"]]
for item in array {
item["rank"] = "advanced" // Generates an @lvalue error
}
// Even though array is immutable, it's of type <Array<Dictionary<String,String>>,
// item is assigned by let automatically.
my $hashref;
method_that_returns_promise
->then(sub {
$hashref = shift;
return 1;
})
->then(sub {
@tempire
tempire / collectionview-beginend-updates.swift
Created August 30, 2015 10:31
collectionview begin/end coredata updates
import Foundation
import UIKit
import CoreData
class PresentationsListVC: UIViewController {
@IBOutlet weak var collectionView: UICollectionView?
// UICollectionView doesn't do beginUpdates/endUpdates.
// CoreData modifications are stored in here and performed together