Skip to content

Instantly share code, notes, and snippets.

View jasonsturges's full-sized avatar

Jason Sturges jasonsturges

View GitHub Profile
@jasonsturges
jasonsturges / noiseWithSmoothness.swift
Last active December 26, 2020 23:02
SpriteKit Procedurally Generated Noise
let noiseTexture = SKTexture(noiseWithSmoothness: 1.1,
size: CGSize(width: 1024, height: 768),
grayscale: false)
let noiseSprite = SKSpriteNode(texture: noiseTexture)
@jasonsturges
jasonsturges / App.svelte
Created December 11, 2020 20:21
3D with Svelte and Babylon.js
<script>
import { onMount } from 'svelte';
import { createScene } from "./scene";
let el;
onMount(() => {
createScene(el)
});
</script>
@jasonsturges
jasonsturges / global.css
Created December 11, 2020 05:28
3D with Svelte and Three.js
html, body {
width: 100%;
height: 100%;
margin: 0;
padding: 0
}
@jasonsturges
jasonsturges / scene.js
Created December 11, 2020 04:34
3D with Svelte and Three.js
import * as THREE from 'three';
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
const geometry = new THREE.BoxGeometry();
const material = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
const cube = new THREE.Mesh(geometry, material);
let renderer;
scene.add(cube);
camera.position.z = 5;
@jasonsturges
jasonsturges / App.svelte
Created December 11, 2020 04:16
3D with Svelte and Three.js
<script>
import { onMount } from 'svelte';
import { createScene } from "./scene";
let el;
onMount(() => {
createScene(el)
});
</script>
@jasonsturges
jasonsturges / main.dev.js
Last active November 30, 2020 05:10
Electron Multiple Windows
const windows = new Set();
export const createWindow = async () => {
if (
process.env.NODE_ENV === 'development' ||
process.env.DEBUG_PROD === 'true'
) {
await installExtensions();
}
@jasonsturges
jasonsturges / performanceNow.js
Created November 22, 2020 02:10
High Resolution Time Stamp
const t0 = performance.now();
Math.log10(n)
const t1 = performance.now();
console.log(`Call took ${t1 - t0} milliseconds.`);
@jasonsturges
jasonsturges / .gitignore
Last active October 30, 2020 16:13
Global .gitignore
# JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm
## Directory-based project format
.idea/
## File-based project format
*.ipr
*.iws
*.iml
# Visual Studio Code
.vscode/
@jasonsturges
jasonsturges / benchmark.js
Created August 26, 2020 07:20
Benchmarking JavaScript - Baseline time
const runBaseline = (iterations = 100000000) => {
let startTime = new Date().getTime();
for (let i = 0; i < iterations; i++) {
// no operation
}
let endTime = new Date().getTime();
return endTime - startTime;
}
const runTest = (iterations = 100000000) => {
@jasonsturges
jasonsturges / benchmark.js
Created August 26, 2020 06:51
Benchmarking JavaScript - Asynchronous execution
const runTest = (iterations = 100000000) => {
let startTime = new Date().getTime();
for (let i = 0; i < iterations; i++)
Math.log10(0)
let endTime = new Date().getTime();
let totalTime = endTime - startTime;
let fnTime = (totalTime / iterations).toFixed(10);
let operations = Math.floor(1000 / totalTime * iterations);