Skip to content

Instantly share code, notes, and snippets.

@lg0
lg0 / filename.applescript
Created April 20, 2012 15:57
applescript:get selected filename and extension
tell application "Finder" to set theFile to POSIX path of (selection as alias)
tell application "Finder" to set fileExtension to name extension of (selection as alias)
@mattatz
mattatz / UVTransform.shader
Created April 6, 2015 02:28
Example of uv transform shader for Unity.
Shader "Mattatz/UVTransform" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_TexScale ("Scale of Tex", Float) = 1.0
_TexRatio ("Ratio of Tex", Float) = 1.0
_Theta ("Rotation of Tex", Float) = 0.0
_PlaneScale ("Scale of Plane Mesh", Vector) = (1, 1, 0, 0)
}
@devindazzle
devindazzle / smoothDamp.swift
Created August 23, 2016 12:07
The smoothDamp function in Unity implemented using Swift
/**
* Gradually changes a value towards a desired goal over time - implemented from Unity C#
*/
public func smoothDamp(current c: CGFloat, target t: CGFloat, currentVelocity: inout CGFloat, smoothTime time: CGFloat, maxSpeed: CGFloat = CGFloat.infinity, deltaTime: CGFloat) -> CGFloat {
let smoothTime = max(0.0001, time)
let num = 2 / smoothTime
let num2 = num * deltaTime
let num3 = 1 / (1 + num2 + 0.48 * num2 * num2 + 0.235 * num2 * num2 * num2)
var num4 = c - t
let num5 = t
@krzys-h
krzys-h / UnityWebRequestAwaiter.cs
Created July 20, 2018 22:47
[Unity] Use UnityWebRequest with async/await
public class UnityWebRequestAwaiter : INotifyCompletion
{
private UnityWebRequestAsyncOperation asyncOp;
private Action continuation;
public UnityWebRequestAwaiter(UnityWebRequestAsyncOperation asyncOp)
{
this.asyncOp = asyncOp;
asyncOp.completed += OnRequestCompleted;
}
using UnityEngine.UI;
[RequireComponent(typeof(RectTransform), typeof(LayoutElement))]
[ExecuteInEditMode]
public class LayoutElementFitParent : MonoBehaviour
{
[SerializeField] private float aspectRatio = 1;
[SerializeField] private bool updateMin = false;
[SerializeField] private bool updatePreferred = false;
@walterpalladino
walterpalladino / Open Unity 16-9.scpt
Created October 18, 2018 16:36
How to Open the Unity Window on Mac OS X on a 16:9 relationship (1280x720)
tell application "Unity" to activate -- needs to be in front
tell application "System Events" to tell application process "Unity"
try
get properties of window 1
set size of window 1 to {1280, 720}
on error errmess
log errmess
-- no window open
end try
end tell
@danamuise
danamuise / Earthquake frag shader
Created December 28, 2018 19:38
This is a GLSL post processor frag shader used in AR Spark (Facebook Messenger AR effects). It creates a random UV shaking effect.
varying vec2 hdConformedUV;
varying vec2 uv;
uniform sampler2D inputImage;
uniform int passIndex;
uniform vec2 uRenderSize;
uniform float uTime;
float random (in vec2 st)
{
return fract(sin(dot(st.xy, vec2(12.9898,78.233)))* 43758.5453123);
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
// Laser Focused
// Ben Ursu | Afrosquared
// Spark AR Studio
// Instagram | https://www.instagram.com/a/r/?effect_id=206763150244323
@lassemt
lassemt / script.js
Created January 15, 2020 19:45
SparkAR requestAnimationFrame alternative.
const t = require('Time');
const D = require('Diagnostics');
const Scene = require('Scene');
const objText = Scene.root.find('2dText0');
let frame = 0;
const round = (val, precision = 1) => {
const multiplier = Math.pow(10, precision || 0);
return Math.round(val * multiplier) / multiplier;
@celian-rib
celian-rib / useScrollBlock.ts
Last active May 24, 2024 08:54 — forked from reecelucas/useScrollBlock.js
React hook to enable/disable page scroll (Typescript version)
import { useRef } from 'react';
const safeDocument: Document = document;
/**
* Usage:
* const [blockScroll, allowScroll] = useScrollBlock();
*/
export const useScrollBlock = (): [() => void, () => void] => {
const scrollBlocked = useRef(false);