Skip to content

Instantly share code, notes, and snippets.

View alexwal's full-sized avatar
❤️
🧡💛💚💙💜🖤

Alexander Walczak alexwal

❤️
🧡💛💚💙💜🖤
  • New York, NY
View GitHub Profile
// Safely Modifying The View State (SwiftUI)
// https://swiftui-lab.com
// https://swiftui-lab.com/state-changes
import SwiftUI
struct CustomView: View {
var body: some View {
NavigationView {
@alexwal
alexwal / generateRandomPastelColor.swift
Last active March 5, 2021 21:40 — forked from JohnCoates/generateRandomPastelColor.swift
Randomly generate pastel UIColor in Swift
// Adapted from Stack Overflow answer by David Crow http://stackoverflow.com/a/43235
// Question: Algorithm to randomly generate an aesthetically-pleasing color palette by Brian Gianforcaro
// Method randomly generates a pastel color, and optionally mixes it with another color
import UIKit
func randomPastelColor(mixedWith mixColor: UIColor? = nil) -> UIColor {
// Mix the color
let mixColor: UIColor = mixColor ?? .lightGray
var mixRed: CGFloat = 0, mixGreen: CGFloat = 0, mixBlue: CGFloat = 0;
@alexwal
alexwal / share_variables_decorator.py
Created December 27, 2018 22:19 — forked from danijar/share_variables_decorator.py
TensorFlow decorator to share variables between calls. Works for both functions and methods.
import functools
import tensorflow as tf
class share_variables(object):
def __init__(self, callable_):
self._callable = callable_
self._wrappers = {}
@alexwal
alexwal / mergesort.py
Last active November 27, 2021 03:46 — forked from jogi/mergesort.py
Recursive Mergesort in Python
# Alex Walczak, 2017
# Simple recursive merge sort implementation.
def merge(left, right):
if not (len(left) and len(right)):
return left or right
result = []
i = j = 0
while len(result) < len(left) + len(right):
if i == len(left) or j == len(right):
@alexwal
alexwal / cluster_barrier_for_tensorflow.py
Last active March 27, 2020 07:13 — forked from yaroslavvb/simple_barrier.py
Example of using shared counters to implement Barrier primitive
'''
Alex Walczak, 2017
Example of barrier implementation using TensorFlow shared variables
across a multi-machine cluster.
All workers synchronize on the barrier, copy global parameters to local versions,
and increment the global parameter variable asynchronously.
On each worker run: