Skip to content

Instantly share code, notes, and snippets.

View hboon's full-sized avatar
Indie hacking

Hwee-Boon Yar hboon

Indie hacking
View GitHub Profile
@chriseidhof
chriseidhof / boilerplate.swift
Last active December 11, 2024 13:54
QuickMacApp
// Run any SwiftUI view as a Mac app.
import Cocoa
import SwiftUI
NSApplication.shared.run {
VStack {
Text("Hello, World")
.padding()
.background(Capsule().fill(Color.blue))
@warpling
warpling / CAMediaTimingFunction.swift
Last active August 22, 2024 15:19
Better CAMediaTimingFunctions
//
// CAMediaTimingFunction.swift
import UIKit
extension CAMediaTimingFunction {
static let linear = CAMediaTimingFunction(name: .linear)
static let easeOut = CAMediaTimingFunction(name: .easeOut)
@dideler
dideler / bot.rb
Last active December 5, 2024 17:11
Sending a notification message to Telegram using its HTTP API via cURL
# Use this script to test that your Telegram bot works.
#
# Install the dependency
#
# $ gem install telegram_bot
#
# Run the bot
#
# $ ruby bot.rb
#
@kolodny
kolodny / post.md
Created April 17, 2018 13:40
Swift State Machine

Fully Exhaustive Swift State Machine

The following is a nice Swift pattern to make a vanilla Swift state machine:

class Machine {
  enum State {
    case foo
    case bar(String)
    case baz(Int)
@hboon
hboon / using-ipsidekick-with-numbers-app.scpt
Last active October 15, 2017 14:49
Using IP Sidekick for geolocation in Numbers.app
//Using IP Sidekick for geolocation in Numbers.app
//hboon@motionobj.com
//https://ipsidekick.com
//Instructions:
//1. Save this file as using-ipsidekick-with-numbers-app.scpt in Script Editor.app
//2. In Numbers app, open your spreadsheet and select the cells with IP address
//..you want to lookup and run this script in Script Editor.app
@insidegui
insidegui / WebCacheCleaner.swift
Created September 14, 2016 23:12
Clear WKWebView's cookies and website data storage, very useful during development.
import Foundation
import WebKit
final class WebCacheCleaner {
class func clean() {
HTTPCookieStorage.shared.removeCookies(since: Date.distantPast)
print("[WebCacheCleaner] All cookies deleted")
WKWebsiteDataStore.default().fetchDataRecords(ofTypes: WKWebsiteDataStore.allWebsiteDataTypes()) { records in
@mheiber
mheiber / jscore.md
Last active January 31, 2024 17:42
Using JavaScriptCore in a Production iOS app

OUTDATED

JavaScriptCore is a built-in iOS library that enables you to use JavaScript in apps alongside Objective-C and Swift. It lets developers read JavaScript from a string, execute it from Objective-C or Swift, and share data structures and functions across languages. We JavaScriptCore to share code between Web and iOS.

@gwillem
gwillem / ansible-bootstrap-ubuntu-16.04.yml
Created June 16, 2016 21:59
Get Ansible to work on bare Ubuntu 16.04 without python 2.7
# Add this snippet to the top of your playbook.
# It will install python2 if missing (but checks first so no expensive repeated apt updates)
# gwillem@gmail.com
- hosts: all
gather_facts: False
tasks:
- name: install python 2
raw: test -e /usr/bin/python || (apt -y update && apt install -y python-minimal)
@dtorres
dtorres / NSURLBackgroundSessionBits.m
Created November 2, 2015 21:18
Storing Info in background requests.
/*
Basically what we are going to do is use and profit from NSURLRequests being conformant to NSCoding,
and a little known API from NSURLProtocol which allows us attach info to requests.
*/
//Step 0: For the purpose of this gist, we'll already have a background session setup and assume a bunch of stuff.
NSURLSession *bgSession = [NSURLSession magicMethodWhichGivesMeTheAlreadySetupSession]; //Geeez, Methods are long in Obj-C.
//IMPORTANT: Request must be mutable in order for this to work. Got an immutable one. Make a copy. Can't? Well, Make it so!.
//Step 1: Setup your basic request.
@gnestor
gnestor / custom.rb
Created February 21, 2015 03:39
RubyMotion: Custom rake tasks for New Relic, Testflight (old), and Crittercism
def build_path
"build/iPhoneOS-7.0-Release/"
end
def ipa_name
"APP_FILE_NAME.ipa"
end
def dsym_name
"APP_FILE_NAME.app.dSYM"