Skip to content

Instantly share code, notes, and snippets.

View sorted-bits's full-sized avatar

Wim Haanstra sorted-bits

View GitHub Profile
@sorted-bits
sorted-bits / README.md
Created March 27, 2024 06:18
Getting Bluetooth to work on HomeAssistant Docker on Ubuntu 23

Dockerfile

Volumes

Make sure you have the following volume mounted in your Dockerfile:

volumes:
  - /var/run/dbus:/var/run/dbus
assert(getprop("ro.product.device") == "charlotte" || getprop("ro.build.product") == "charlotte" ||
getprop("ro.product.device") == "kirin970" || getprop("ro.build.product") == "kirin970" || abort("E3004: This package is for device: charlotte,kirin970; this device is " + getprop("ro.product.device") + "."););
assert(huawei.verify_vendor_build_id("P") == "1");
ui_print("Target: Huawei/lineage_charlotte/charlotte:9/PQ3A.190801.002/4eade15b97:userdebug/release-keys");
ifelse(is_mounted("/system"), unmount("/system"));
package_extract_dir("install", "/tmp/install");
set_metadata_recursive("/tmp/install", "uid", 0, "gid", 0, "dmode", 0755, "fmode", 0644);
set_metadata_recursive("/tmp/install/bin", "uid", 0, "gid", 0, "dmode", 0755, "fmode", 0755);
mount("ext4", "EMMC", "/dev/block/bootdevice/by-name/system", "/system", "");
run_program("/tmp/install/bin/backuptool.sh", "backup", "/system/system");
@sorted-bits
sorted-bits / SBCircleProgressBar.h
Created November 19, 2011 07:19
A circle as progressbar
//
// SBCircleProgressBar.h
//
// Created by Wim Haanstra on 17-11-11.
// Copyright (c) 2011 Sorted Bits. All rights reserved.
//
@interface SBCircleProgressBar : UIView
// The maximum value of the progressbar
@sorted-bits
sorted-bits / gist:1302265
Created October 20, 2011 20:28
NSURLConnection in its own thread
NSString* url = @"http://your.url/here";
NSURL* nsurl = [NSURL URLWithString:url];
NSMutableURLRequest* urlReq = [[NSMutableURLRequest alloc] initWithURL:nsurl];
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:urlReq delegate:self];
while(!finished) {
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
}
- (void) connectionDidFinishLoading:(NSURLConnection *)connection
@sorted-bits
sorted-bits / gist:1302242
Created October 20, 2011 20:21
Placing curved text on an UIImage
NSArray* sections = [[NSArray alloc] initWithObjects:@"text1", @"text2", @"text3", @"text4", nil];
- (UIImage*) createMenuRingWithFrame:(CGRect)frame
{
// First fix the frame to make sure it uses the right scaling (iPhone 4 / iPad compatibility).
frame = CGRectMake(frame.origin.x, frame.origin.y, frame.size.width * scale, frame.size.height * scale);
// Same for the text radius
float scaledTextRadius = textRadius * scale;
float scaledRingWidth = ringWidth;
@sorted-bits
sorted-bits / gist:1302091
Created October 20, 2011 19:36
shouldAllowRotateToInterfaceOrientation implementation
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return [WHUtilities shouldAllowRotateToInterfaceOrientation:interfaceOrientation];
}
@sorted-bits
sorted-bits / gist:1302080
Created October 20, 2011 19:33
Encryption & decryption
public static string Encrypt(this string Message, string passphrase = "")
{
if (passphrase == "")
passphrase = ConfigurationManager.AppSettings["encrpytionPassphrase"];
byte[] Results;
System.Text.UTF8Encoding UTF8 = new System.Text.UTF8Encoding();
MD5CryptoServiceProvider HashProvider = new MD5CryptoServiceProvider();
byte[] TDESKey = HashProvider.ComputeHash(UTF8.GetBytes(passphrase));
@sorted-bits
sorted-bits / gist:1302074
Created October 20, 2011 19:31
MD5 and SHA1 hashing
public static string ToSHA1(this string text, Encoding enc)
{
byte[] buffer = enc.GetBytes(text);
SHA1CryptoServiceProvider cryptoTransformSHA1 =
new SHA1CryptoServiceProvider();
string hash = BitConverter.ToString(
cryptoTransformSHA1.ComputeHash(buffer)).Replace("-", "");
return hash;
}
@sorted-bits
sorted-bits / gist:1302069
Created October 20, 2011 19:30
String to valid filename
static public string ToValidFileName(this string name)
{
string invalidChars = Regex.Escape(new string(Path.GetInvalidFileNameChars()));
string invalidReStr = string.Format(@"[{0}]+", invalidChars);
return Regex.Replace(name, invalidReStr, "_");
}
@sorted-bits
sorted-bits / gist:1302057
Created October 20, 2011 19:26
Validating Int from string
public static bool IsInt(this string text)
{
int integer = 0;
return Int32.TryParse(text, out integer);
}