Skip to content

Instantly share code, notes, and snippets.

View valexa's full-sized avatar
💼
Open for work

Vlad Alexa valexa

💼
Open for work
View GitHub Profile
@valexa
valexa / ContentView.swift
Created November 21, 2023 18:59
NavigationStack example
//
// ContentView.swift
// sandbox
//
// Created by vlad on 21/11/2023.
//
import SwiftUI
enum Route {
@valexa
valexa / Enum
Last active March 30, 2020 06:56
Enum updated with new and pro fonts for fontawesome
// Enum.swift
//
// Copyright (c) 2014-present FontAwesome.swift contributors
//
// 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:
@valexa
valexa / SimpleClient.swift
Created June 27, 2018 09:12 — forked from sarpsolakoglu/SimpleClient.swift
Simple Swift 4 Rest Client that uses the Codable protocol for JSON conversion
//
// SimpleClient.swift
//
// Created by Sarp Solakoglu on 18/09/2017.
// Copyright © 2017 Sarp Solakoglu. All rights reserved.
//
import Foundation
enum RestMethod: String {
//1 , cant be right as assigning instance variable does not make a copy
var fooBar = self.fooBar
fooBar.forEach({ foo in
if foo.id == bar.id {
fooBar.remove(at: fooBar.index(of: foo)!)
}
})
self.fooBar = fooBar
//2, seems right as enumerated makes a copy
public func RegexValidationWithMessage(_ message:String, regex:String, allowingNull:Bool = true) -> Validation<String>? {
if let regex = try? NSRegularExpression(pattern: regex, options: .CaseInsensitive) {
return Validation<String>(message: message, validation: { (value) -> Bool in
let nullValidation = NonEmptyStringValidation("")
guard let stringValue = value else {
return false
}
@valexa
valexa / gist:8621322
Created January 25, 2014 18:43
NSDraggingSession
- (void)mouseDown:(NSEvent*)event
{
//create a NSPasteboardItem
NSPasteboardItem *pbItem = [NSPasteboardItem new];
[pbItem setDataProvider:self forTypes:[NSArray arrayWithObjects:NSPasteboardTypeTIFF, nil]];
//create a new NSDraggingItem with our pasteboard item.
NSDraggingItem *dragItem = [[NSDraggingItem alloc] initWithPasteboardWriter:pbItem];
NSPoint dragPosition = [self convertPoint:[event locationInWindow] fromView:nil];
@implementation LaunchButton
- (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Initialization code here.
NSTrackingArea *area = [[NSTrackingArea alloc] initWithRect:NSZeroRect options:NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways | NSTrackingInVisibleRect owner:self userInfo:nil];
[self addTrackingArea:area];
float lastTick = 0.0;
for (int i = 0; i <= 900; i++) {
float t = [self tickX:9 timesOfTotal:900 current:i lastTick:lastTick];
if (t > 0) {
NSLog(@"%f %i",t,i);
lastTick = t;
}
}
NSView *parent = [[NSView alloc] initWithFrame:NSZeroRect];
NSView *child = [[NSView alloc] initWithFrame:NSZeroRect];
[parent addSubview:child];
[child setWantsLayer:YES];
CALayer *childLayer = [child layer];
CATransformLayer *transformLayer = [CATransformLayer layer];
[transformLayer addSublayer:childLayer];
[parent setWantsLayer:YES];
NSLog(@"%@",childLayer);
NSLog(@"%@",transformLayer.sublayers);
[image setWantsLayer:YES];
CALayer *flayer = [image layer];
[flayer removeAllAnimations];
[backImage setWantsLayer:YES];
CALayer *blayer = [backImage layer];
[blayer removeAllAnimations];
NSView *superView = [image superview];
[superView setWantsLayer:YES];