Skip to content

Instantly share code, notes, and snippets.

@Refsa
Refsa / URPSimpleLit.shader
Created October 31, 2020 09:03
Unity - Shader showing how to write a Simple Lit shader for Unity URP
Shader "Custom/URPSimpleLit"
{
Properties
{
_Color ("Color", Color) = (1,0,0,1)
}
SubShader
{
Tags {
"RenderPipeline" = "UniversalPipeline"
@preble
preble / AssertUnwrap.swift
Created September 16, 2020 23:55
This is Nate's idea, something I use on every project. Sometimes you need to accommodate an optional that shouldn't be optional.
public extension Optional {
/// Stop in the debugger in debug builds if self is `.none`.
///
/// Example usage:
///
/// guard let value = maybeValue.assertUnwrap() else { return "bogus value" }
///
func assertUnwrap(_ message: @autoclosure () -> String? = nil, file: StaticString = #file, function: String = #function, line: UInt = #line) -> Wrapped? {
switch self {
@chriseidhof
chriseidhof / boilerplate.swift
Last active January 3, 2024 05:54
QuickMacApp
// Run any SwiftUI view as a Mac app.
import Cocoa
import SwiftUI
NSApplication.shared.run {
VStack {
Text("Hello, World")
.padding()
.background(Capsule().fill(Color.blue))
import Combine
// When wrapping a value, we take advantage of the setter
// to feed a PassthroughSubject
@propertyWrapper
struct Published<T> {
private var innerValue: T
private let innerSubject = PassthroughSubject<T, Never>()
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var rootVC: UINavigationController? = nil
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
window = UIWindow(frame: UIScreen.main.bounds)
extension CGPoint {
init(_ size: CGSize) {
self.x = size.width
self.y = size.height
}
init(_ vector: SCNVector3) {
self.x = CGFloat(vector.x)
self.y = CGFloat(vector.y)
@miguelmota
miguelmota / buildspec.yml
Last active October 18, 2021 03:23
AWS CodePipeline CodeBuild middleman build deploy to S3 and invalidate cloudfront cache
version: 0.1
phases:
install:
commands:
- apt-get update
- apt-get install nodejs -y
- gem install bundler
- gem install middleman
pre_build:
commands:
@tntmeijs
tntmeijs / unitythreedimensionalperlinnoise.cs
Last active February 19, 2024 01:52
A 3D implementation using the 2D Perlin noise function of Unity3D.
public static float Noise3D(float x, float y, float z, float frequency, float amplitude, float persistence, int octave, int seed)
{
float noise = 0.0f;
for (int i = 0; i < octave; ++i)
{
// Get all permutations of noise for each individual axis
float noiseXY = Mathf.PerlinNoise(x * frequency + seed, y * frequency + seed) * amplitude;
float noiseXZ = Mathf.PerlinNoise(x * frequency + seed, z * frequency + seed) * amplitude;
float noiseYZ = Mathf.PerlinNoise(y * frequency + seed, z * frequency + seed) * amplitude;
@wkwiatek
wkwiatek / app-1.spec.ts
Last active December 17, 2021 01:52
Angular 2 test snippets for Angular final version. Codebase for https://developers.livechatinc.com/blog/category/programming/angular-2/
// App
import { Component } from '@angular/core';
@Component({
selector: 'app',
template: '<span>{{ sayHello() }}</span>',
})
export class App {
public name: string = 'John';
import UIKit
protocol NibLoadable: class {
typealias Object
static var nibName: String { get }
static var nib: UINib { get }
static var firstObjectFromNib: AnyObject? { get }
}
extension NibLoadable {