Skip to content

Instantly share code, notes, and snippets.

View cupnoodle's full-sized avatar

soulchild cupnoodle

View GitHub Profile
@cupnoodle
cupnoodle / toggleSync.md
Last active November 13, 2023 15:11
Disable sync of NSPersistentCloudKitContainer at launch, then enable sync later

To disable iCloud sync of core data when the app launches, set the cloudKitContainerOptions to nil for the persistent store.

In your AppDelegate.swift file :

lazy var persistentContainer: NSPersistentCloudKitContainer = {

        let container = NSPersistentCloudKitContainer(name: "your core data container name")
        
        guard let description = container.persistentStoreDescriptions.first else {
            fatalError("###\(#function): Failed to retrieve a persistent store description.")
@cupnoodle
cupnoodle / shopify_api_bug_report_template.txt
Created November 8, 2023 09:19
Shopify API Bug Report Template (use this so you can reply one less email)
What is the App ID and name?
What is the expected outcome of using the app? And what's happening instead of that intended outcome?
Timeframe - when did this start happening or, if it worked previously, when did it stop working?
Is the issue affecting a certain store, or multiple merchants? Please share the affected store(s) here:
@cupnoodle
cupnoodle / imagemagick.sh
Created December 16, 2019 17:28
Install ImageMagick on Ubuntu 18.04 with HEIF / HEIC support
sudo sed -Ei 's/^# deb-src /deb-src /' /etc/apt/sources.list
sudo apt-get update
sudo apt-get install build-essential autoconf libtool git-core
sudo apt-get build-dep imagemagick libmagickcore-dev libde265 libheif
cd /usr/src/
sudo git clone https://github.com/strukturag/libde265.git
sudo git clone https://github.com/strukturag/libheif.git
cd libde265/
sudo ./autogen.sh
sudo ./configure
@cupnoodle
cupnoodle / IAPHelper.swift
Created July 21, 2020 09:51
In app purchase helper class
// Created by Soulchild on 21/07/2020.
// Copyright © 2020 fluffy. All rights reserved.
//
import Foundation
import StoreKit
// Need to install the TPInAppReceipt library first
import TPInAppReceipt
@cupnoodle
cupnoodle / delayedExpectation.swift
Created June 20, 2018 11:18
Swift unit test with delay to wait the UI to present
let alertExpectation = XCTestExpectation(description: "testAlertShouldAppear")
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0, execute: {
XCTAssertTrue(loginVC.presentedViewController is UIAlertController)
alertExpectation.fulfill()
})
wait(for: [alertExpectation], timeout: 1.5)
@cupnoodle
cupnoodle / proportional.md
Created July 4, 2020 15:32
Proportional Auto Layout Constraint

4 - Using proportion to make layout looks good across different screen size

Ever encounter this? You've put a lot of effort on designing layout / UI for your app in Xcode, finally it looks good after spending hours tweaking it, but when you view it in another device with different screen size, it either looks too cramped with UILabels overlapping each other, or it looks too spacious with a lot of blank space between each elements.

Say you have designed two views to align side by side in iPhone 8 with a fixed width for both of them :

fixedWidth8

@cupnoodle
cupnoodle / rails new.txt
Created July 26, 2022 09:34
Rails 7 - Rails new options
Usage:
rails new APP_PATH [options]
Options:
[--skip-namespace], [--no-skip-namespace] # Skip namespace (affects only isolated engines)
[--skip-collision-check], [--no-skip-collision-check] # Skip collision check
-r, [--ruby=PATH] # Path to the Ruby binary of your choice
# Default: /Users/soulchild/.rubies/ruby-3.1.2/bin/ruby
-m, [--template=TEMPLATE] # Path to some application template (can be a filesystem path or URL)
-d, [--database=DATABASE] # Preconfigure for selected database (options: mysql/postgresql/sqlite3/oracle/sqlserver/jdbcmysql/jdbcsqlite3/jdbcpostgresql/jdbc)
@cupnoodle
cupnoodle / scroll_to_actions.js
Created June 4, 2022 07:44
Scroll to order actions box after loading
<script>
var cancellable_hash = window.location.hash.substr(1);
if(cancellable_hash === 'actions'){
setTimeout(function() {
document.getElementById('cancellable-title').scrollIntoView();
}, 1500);
}
</script>
@cupnoodle
cupnoodle / order_confirmation_template.liquid
Created March 10, 2022 15:38
Order confirmation email template with line item properties
{% unless line.properties == empty %}
<ul style="list-style-type: none; padding: 0;">
{% for property in line.properties %}
<li><span class="order-list__item-variant">{{ property.first }}: {{ property.last }}</span></li>
{% endfor %}
</ul>
{% endunless %}
@cupnoodle
cupnoodle / UILabel+isTruncated.swift
Created February 4, 2020 17:26
Check if UILabel is truncated
extension UILabel {
var isTruncated: Bool {
guard let labelText = text else {
return false
}
let labelTextSize = (labelText as NSString).boundingRect(
with: CGSize(width: frame.size.width, height: .greatestFiniteMagnitude),
options: .usesLineFragmentOrigin,
attributes: [.font: font!],