Skip to content

Instantly share code, notes, and snippets.

View bcattle's full-sized avatar

bcattle bcattle

View GitHub Profile
@devanlai
devanlai / svd-dump.py
Last active March 3, 2023 11:03
gdb script for dumping STM32 registers
"""
Utilities for dumping STM32 peripheral registers with tab-completion
Based on a script by vampi-the-frog
Dependencies:
pip install -U cmsis-svd
Usage (inside gdb):
(gdb) source /path/to/svd-dump.py
@Skorch
Skorch / ios-to-s3-background.swift
Last active January 18, 2021 09:13
Uploading from iOS to S3 as a background task. Pro Tip: You can embed REST parameters in the header, and have the server execute a Lambda on upload.
//:
import Foundation
import AWSS3
//A sample struct to define the parameters to encode and send to the
//server to be executed along with your upload
struct FileUploadParameters{
//label for the encoded name
@stuaxo
stuaxo / processify.py
Last active July 12, 2024 08:32 — forked from schlamar/processify.py
processify
# modified from https://gist.github.com/schlamar/2311116#file-processify-py-L17
# also see http://stackoverflow.com/questions/2046603/is-it-possible-to-run-function-in-a-subprocess-without-threading-or-writing-a-se
import inspect
import os
import sys
import traceback
from functools import wraps
from multiprocessing import Process, Queue
@ZevEisenberg
ZevEisenberg / map float range.swift
Last active July 13, 2020 20:31
Mapping floating point numbers between two ranges in Swift
import QuartzCore
extension CGFloat {
func map(from from: ClosedInterval<CGFloat>, to: ClosedInterval<CGFloat>) -> CGFloat {
let result = ((self - from.start) / (from.end - from.start)) * (to.end - to.start) + to.start
return result
}
}
extension Double {
@daltheman
daltheman / NSData+Compression.swift
Created June 18, 2015 04:32
Simple Swift NSData Extension that shows how to use Apple LZFSE Compression Algorithm
/*
NSData+Compression.swift
Created by Danilo Altheman on 17/06/15.
The MIT License (MIT)
Copyright © 2015 Quaddro - Danilo Altheman. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
@AliSoftware
AliSoftware / struct_vs_inheritance.swift
Last active March 27, 2024 11:57
Swift, Struct & Inheritance: How to balance the will of using Struct & Value Types and the need for Inheritance?
// #!Swift-1.1
import Foundation
// MARK: - (1) classes
// Solution 1:
// - Use classes instead of struct
// Issue: Violate the concept of moving model to the value layer
// http://realm.io/news/andy-matuschak-controlling-complexity/
BOOL isDeviceJailbroken()
{
#if !TARGET_IPHONE_SIMULATOR
//Apps and System check list
BOOL isDirectory;
if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"/%@%@%@%@%@%@%@", @"App", @"lic",@"ati", @"ons/", @"Cyd", @"ia.a", @"pp"]]
|| [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"/%@%@%@%@%@%@%@", @"App", @"lic",@"ati", @"ons/", @"bla", @"ckra1n.a", @"pp"]]
|| [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"/%@%@%@%@%@%@%@", @"App", @"lic",@"ati", @"ons/", @"Fake", @"Carrier.a", @"pp"]]
@gimenete
gimenete / gist:53704124583b5df3b407
Last active July 31, 2020 16:20
Animated rootViewController transition
// put this in your AppDelegate
- (void)changeRootViewController:(UIViewController*)viewController {
if (!self.window.rootViewController) {
self.window.rootViewController = viewController;
return;
}
UIView *snapShot = [self.window snapshotViewAfterScreenUpdates:YES];
[viewController.view addSubview:snapShot];
self.window.rootViewController = viewController;
@gitaarik
gitaarik / git_submodules.md
Last active August 1, 2024 03:20
Git Submodules basic explanation

Git Submodules basic explanation

Why submodules?

In Git you can add a submodule to a repository. This is basically a repository embedded in your main repository. This can be very useful. A couple of usecases of submodules:

  • Separate big codebases into multiple repositories.
@justinmstuart
justinmstuart / NSArray+Statistics.m
Last active June 14, 2019 03:36
Calculate Summary Statistics for Array: Sum, Mean, Min, Max, Standard Deviation
#import "NSArray+Statistics.h"
@implementation NSArray (Statistics)
- (NSNumber *)sum {
NSNumber *sum = [self valueForKeyPath:@"@sum.self"];
return sum;
}
- (NSNumber *)mean {