Skip to content

Instantly share code, notes, and snippets.

View dkarbayev's full-sized avatar
🏠
Working from home

Dan Karbayev dkarbayev

🏠
Working from home
  • Army of One
  • Your Neighbourhood
View GitHub Profile
@chriseidhof
chriseidhof / sample.swift
Last active June 11, 2024 06:11
View Inspection
import SwiftUI
struct SizeKey: PreferenceKey {
static func reduce(value: inout CGSize?, nextValue: () -> CGSize?) {
value = value ?? nextValue()
}
}
struct ContentView: View {
@State var width: CGFloat? = nil
var body: some View {
// Advanced SwiftUI Transitions
// https://swiftui-lab.com
// https://swiftui-lab.com/advanced-transitions
import SwiftUI
struct CrossEffectDemo: View {
let animationDuration: Double = 2
let images = ["photo1", "photo2", "photo3", "photo4"]
@State private var idx = 0
@marcedwards
marcedwards / twister.pde
Last active April 16, 2021 12:43
A twisty 3D effect using a 2D image, created with Processing
// A sin-y, wobbly, twisty, 3D-looking thing that slices up an image to create its effect.
// For more information and to download the image required, visit:
// https://dribbble.com/shots/5843126-Twisty-3D-effect-using-a-2D-image
//
// Place the image inside a folder called “data” alongside the Processing sketch for it to work.
// Created using Processing 3.4.
//
// Code by @marcedwards from @bjango.
PImage twist;
@albertbori
albertbori / StackCollectionView.swift
Last active August 9, 2018 10:14
An example of a UICollectionView-like view made from UIStackViews for easy layout of small grids
//
// StackCollectionView.swift
//
// Created by Albert Bori on 6/23/17.
//
import UIKit
@IBDesignable
class StackCollectionView: UIView {
@jay18001
jay18001 / Matrix4.swift
Created February 24, 2017 02:57
Swift version of helper class from Ray Wenderlich: Metal Tutorial with Swift 3 Part 2
import UIKit
import GLKit
extension Float {
var radians: Float {
return GLKMathDegreesToRadians(self)
}
}
class Matrix4 {
@JedWatson
JedWatson / KeystoneApiExample.md
Last active July 26, 2021 11:29
Example of how to scaffold API endpoints for Posts in a Keystone project (based on the yo keystone example).

This is an example of how to scaffold API endpoints to list / get / create / update / delete Posts in a Keystone website.

It's a modification of the default project created with the yo keystone generator (see https://github.com/JedWatson/generator-keystone)

Gists don't let you specify full paths, so in the project structure the files would be:

routes-index.js        -->    /routes/index.js         // modified to add the api endpoints
routes-api-posts.js    -->    /routes/api/posts.js     // new file containing the Post API route controllers
@mikevoyt
mikevoyt / gist:4613982
Last active February 8, 2023 12:52
Example of how to create a pinned header with UICollectionView (i.e., a header that doesn't scroll with the rest of the cells). As simple as possible - assumes a single header, at index path [0,0], to be pinned at the top of the collection view.
//Override UICollectionViewFlowLayout class
@interface FixedHeaderLayout : UICollectionViewFlowLayout
@end
@implementation FixedHeaderLayout
//Override shouldInvalidateLayoutForBoundsChange to require a layout update when we scroll
- (BOOL) shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds {
return YES;
}
@ecarter
ecarter / mapOrder.js
Created December 2, 2011 15:40
Order an array of objects based on another array order
/**
* Sort array of objects based on another array
*/
function mapOrder (array, order, key) {
array.sort( function (a, b) {
var A = a[key], B = b[key];