Skip to content

Instantly share code, notes, and snippets.

View krzysztofzablocki's full-sized avatar

Krzysztof Zabłocki krzysztofzablocki

View GitHub Profile
@krzysztofzablocki
krzysztofzablocki / mac-list-bug.swift
Last active April 5, 2021 14:06
Why isn't last delete refreshing the list? Mac example
@main
struct ListBugApp: App {
var body: some Scene {
WindowGroup {
NavigationView { // comment out navigation view and list works
ContentView()
Text("Detail")
}
}
}
// Copyright (c) 2021 Manuel Maly
// 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 the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all
require 'mechanize'
require 'moving_average'
mechanize = Mechanize.new
login_page = mechanize.get 'https://www.myfitnesspal.com/account/login'
form = login_page.forms.first
# noinspection RubyResolve
form.field_with(id: 'username').value = "username"
form.field_with(id: 'password').value = "pass"
form.submit
@krzysztofzablocki
krzysztofzablocki / gist:4091783
Created November 16, 2012 23:13
Free memory on iOS
-(float) get_free_memory {
mach_port_t host_port;
mach_msg_type_number_t host_size;
vm_size_t pagesize;
host_port = mach_host_self();
host_size = sizeof(vm_statistics_data_t) / sizeof(integer_t);
host_page_size(host_port, &pagesize);
vm_statistics_data_t vm_stat;
if (host_statistics(host_port, HOST_VM_INFO, (host_info_t)&vm_stat, &host_size) != KERN_SUCCESS) {
@krzysztofzablocki
krzysztofzablocki / gist:8913213
Last active January 25, 2018 22:06
Diet setup for cutting, paste into calca.io and modify stats.
# For training rest 5 min on compounds, 3-5 minutes on smaller ones
# Training A (first set to failure, second set -10% weight + 1 rep):
# Deadlift - 2x4-5
# Overhead Press - 1x6-8
# Weighted Chinup - 2x4-6
# Chest-Supported Rows - 2x6-8
# Close-grip chinup - 1x6-10
# Training B (first set to failure, second set -10% weight + 1 rep):
button.onTouchUpInside(context: self) { context in
// doStuff
}
@krzysztofzablocki
krzysztofzablocki / template.stencil
Last active January 14, 2017 15:22
AutoEquatable template
// swiftlint:disable file_length
fileprivate func compareOptionals<T>(lhs: T?, rhs: T?, compare: (_ lhs: T, _ rhs: T) -> Bool) -> Bool {
switch (lhs, rhs) {
case let (lValue?, rValue?):
return compare(lValue, rValue)
case (nil, nil):
return true
default:
return false
@krzysztofzablocki
krzysztofzablocki / gist:3305468
Created August 9, 2012 16:06
UITableViewCell + representedObject
// Created by Krzysztof Zabłocki
@interface UITableViewCell (representedObject)
@property (nonatomic, strong) id representedObject;
@end
#import "UITableViewCell+representedObject.h"
#import <objc/runtime.h>
static char RepresentedObjectKey;
import UIKit
import XCPlayground
XCPlaygroundPage.currentPage.needsIndefiniteExecution = true
func perform(initial: Int) {
var value: Int = initial
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1), dispatch_get_main_queue()) { [myConstant = value] in
print("constant in first block \(myConstant)")
print("captured \(value)")
value = initial * 2
@krzysztofzablocki
krzysztofzablocki / gist:3951442
Created October 25, 2012 08:34
Image decompression
+ (UIImage *)decompressedImageWithImage:(UIImage *)image resizeTo:(CGSize)targetSize
{
CGImageRef imageRef = image.CGImage;
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGImageAlphaInfo alphaInfo = CGImageGetAlphaInfo(imageRef);
BOOL sameSize = NO;
if (CGSizeEqualToSize(targetSize, CGSizeMake(CGImageGetWidth(imageRef), CGImageGetHeight(imageRef)))) {
targetSize = CGSizeMake(1, 1);
sameSize = YES;
}