Skip to content

Instantly share code, notes, and snippets.

View MosheBerman's full-sized avatar

Moshe MosheBerman

View GitHub Profile
@smic
smic / BorderlessWindow.swift
Last active July 7, 2023 20:19
Extension to create borderless windows in SwiftUI
import SwiftUI
extension CGRect {
fileprivate func point(anchor: UnitPoint) -> CGPoint {
var point = self.origin
point.x += self.size.width * anchor.x
#if os(macOS)
point.y += self.size.height * (1 - anchor.y)
#else
point.y += self.size.height * anchor.y
@xtabbas
xtabbas / SnapCarousel.swift
Created May 10, 2020 18:13
A carousel that snap items in place build on top of SwiftUI
//
// SnapCarousel.swift
// prototype5
//
// Created by xtabbas on 5/7/20.
// Copyright © 2020 xtadevs. All rights reserved.
//
import SwiftUI
extension UITableView {
func animateSection<Element: Equatable>(section: Int, from:[Element], to: [Element], rowAnimation: UITableViewRowAnimation = .Top) {
assert(from.containsUniqueElements() && to.containsUniqueElements(), "\(#function) can only be used if all elements in the collection are unique.")
func path(index: Int) -> NSIndexPath {
return NSIndexPath(forRow: index, inSection: section)
}
// Find indexes in the old array that should be deleted
@janselv
janselv / UIBezierPathLength.swift
Last active March 8, 2023 08:20
Get total iOS CGPath length as an extension of UIBezierPath written in swift
// The MIT License (MIT)
//
// Copyright (c) 2016 Jansel Valentin
//
// 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:
# Require imagemagick
# require potrace
# sudo apt-get install imagemagick potrace
import os
import argparse
import glob
parser = argparse.ArgumentParser()
parser.add_argument(
"files", type=str, help="png2svg", nargs="*"
@nyg
nyg / iOSCreatePDF.swift
Last active April 2, 2024 11:09
iOS, Swift: Create a PDF file from an HTML string.
// Thanks to http://www.labs.saachitech.com/2012/10/23/pdf-generation-using-uiprintpagerenderer
// Note: including images in the HTML won't work, see here:
// https://github.com/nyg/HTMLWithImagesToPDF
import UIKit
// 1. Create a print formatter
let html = "<b>Hello <i>World!</i></b>"
let fmt = UIMarkupTextPrintFormatter(markupText: html)
@appsandwich
appsandwich / MKMapView+Extensions
Created January 10, 2014 15:04
Get & set the zoom level of a MKMapView
@interface MKMapView (Extensions)
-(double)as_zoomLevel;
-(void)as_setCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate zoomLevel:(NSUInteger)zoomLevel animated:(BOOL)animated;
@end
static double mercadorRadius = 85445659.44705395;
static double mercadorOffset = 268435456;
@MosheBerman
MosheBerman / gist:3972164
Created October 29, 2012 07:38
Return a substring that fits a given rect
//
// NSString+MBDialogString.m
// TileParser
//
// Created by Moshe Berman on 9/23/12.
//
//
#import "NSString+MBDialogString.h"
@plantpurecode
plantpurecode / gist:3703384
Created September 12, 2012 00:57
Recursion, with blocks!
- (void)printRecursivelyUpTo:(NSUInteger)max {
__block dispatch_block_t block;
__block NSUInteger iterator = 0;
dispatch_block_t b = ^{
if(iterator == max) return;
NSLog(@"%u", iterator);
++iterator;
block();
};
@ykarikos
ykarikos / png2svg.sh
Created June 7, 2012 22:17
Convert png to svg using imagemagick and potrace
#!/bin/bash
if [ "$1" == "" ]; then
echo Usage: $0 pngfile
exit 0;
fi
FILE=`basename $1 .png`
if [ ! -e $FILE.png ]; then