Skip to content

Instantly share code, notes, and snippets.

def create_discount(order)
return if order.coupon_credits.reload.detect { |credit| credit.adjustment_source_id == self.id }
if eligible?(order) and amount = calculator.compute(order.line_items)
amount = order.item_total if amount > order.item_total
order.coupon_credits.reload.clear unless combine? and order.coupon_credits.all? { |credit| credit.adjustment_source.combine? }
order.save
coupon_credits.create({
:order => order,
#:amount => amount, #exclude this key / value to force recalculation
:description => "#{I18n.t(:coupon)} (#{code})"
CheckoutsController.class_eval do
# customized verison of the standard r_c update method (since we need to handle gateway errors, etc)
def update
load_object
# call the edit hooks for the current step in case we experience validation failure and need to edit again
edit_hooks
@checkout.enable_validation_group(@checkout.state.to_sym)
@prev_state = @checkout.state
<CBL_FMDatabase: 0x7fd8b2c26880> executeQuery: SELECT sequence, revid, deleted FROM revs WHERE doc_id=? AND current ORDER BY sequence DESC
obj: 5887
>>>>>>>>>>>>>>>>>>>>>>>>> 7 total Conflicts for: f8ee7974-9558-4ba4-ba94-6a7ce98c58b4
<CBL_FMDatabase: 0x7fd8b2c26880> executeUpdate: SAVEPOINT cbl_1
14:15:00.826| CBLDatabase: Begin transaction (level 1)...
14:15:00.826| CBLDatabase: PUT rev={f8ee7974-9558-4ba4-ba94-6a7ce98c58b4 #(null) DEL}, prevRevID=114-b119801ccce39c63560dd7a3576a38ea, allowConflict=0
<CBL_FMDatabase: 0x7fd8b2c26880> executeUpdate: SAVEPOINT cbl_2
14:15:00.827| CBLDatabase: Begin transaction (level 2)...
<CBL_FMDatabase: 0x7fd8b2c26880> executeQuery: SELECT revid, deleted FROM revs WHERE doc_id=? and current=1 ORDER BY deleted asc, revid desc LIMIT 2
obj: 5887
// UITableView+Appearance.h
// - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface UITableView (Appearance)<UIAppearance>
@property (nonatomic, assign) CGFloat footerViewHeight UI_APPEARANCE_SELECTOR;
@end
NS_ASSUME_NONNULL_END
// UITableView+Appearance.h
// - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface UITableView (Appearance)<UIAppearance>
@property (nonatomic, assign) CGFloat footerViewHeight UI_APPEARANCE_SELECTOR;
@end
NS_ASSUME_NONNULL_END
// UITableView+Appearance.h
// - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface UITableView (Appearance)<UIAppearance>
@property (nonatomic, assign) CGFloat footerViewHeight UI_APPEARANCE_SELECTOR;
@end
NS_ASSUME_NONNULL_END
// UITableView+Appearance.h
// - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface UITableView (Appearance)<UIAppearance>
@property (nonatomic, assign) CGFloat footerViewHeight UI_APPEARANCE_SELECTOR;
@end
NS_ASSUME_NONNULL_END
// UITableView+Appearance.h
// - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface UITableView (Appearance)<UIAppearance>
@property (nonatomic, assign) CGFloat footerViewHeight UI_APPEARANCE_SELECTOR;
@end
NS_ASSUME_NONNULL_END
import Foundation
import SwiftUI
class ViewModel: ObservableObject {
var downloadURL = URL(string: "https://i.redd.it/dwlyzl73nv071.jpg")!
@Published var downsampledImage: Image?
func downloadResourceToURL(optimize: Bool, width: CGFloat) {
@lightandshadow68
lightandshadow68 / PostEdit.swift
Last active July 17, 2023 17:48
Vanilla SwiftUI Core Data edit
import SwiftUI
import CoreData
struct PostEditView: View {
@ObservedObject var post: Post
@Environment(\.managedObjectContext) var moc
@State var hasChanges: Bool = false
var body: some View {