Skip to content

Instantly share code, notes, and snippets.

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

Alexander Walczak alexwal

❤️
🧡💛💚💙💜🖤
  • New York, NY
View GitHub Profile
import Foundation
import Gridicons
import UIKit
import WebKit
class WebViewController: UIViewController {
let webView = WKWebView()
let progressView = WebProgressView()
let toolbar = UIToolbar()
let titleView = NavigationTitleView()

Disable Device Enrollment Notification on Mac.md

Restart the Mac in Recovery Mode by holding Comment-R during restart

Open Terminal in the recovery screen and type

csrutil disable
@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:
@danijar
danijar / share_variables_decorator.py
Last active November 20, 2021 17:21
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 = {}
@IanKeen
IanKeen / Codable+InnerArrays.swift
Last active March 3, 2022 00:57
Skipping nested wrappers in json w/ Codable
extension KeyedDecodingContainer {
func decode<T: Decodable, Inner: CodingKey>(_ type: T.Type, forKey key: KeyedDecodingContainer.Key, innerKey: Inner) throws -> [T] {
var array = try nestedUnkeyedContainer(forKey: key)
var items: [T] = []
while !array.isAtEnd {
let container = try array.nestedContainer(keyedBy: Inner.self)
let item = try container.decode(T.self, forKey: innerKey)
items.append(item)
}
# Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License.
# A copy of the License is located at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# or in the "license" file accompanying this file. This file is distributed
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
@alexwal
alexwal / 4Sum.py
Last active September 11, 2018 20:11
Leet Code 4Sum Solution: https://leetcode.com/problems/4sum/
class Solution:
"""
Solution to Leet Code problem 4Sum: https://leetcode.com/problems/4sum/
Runtime: 100 ms beats 93.4% of python3 submissions
"""
def fourSum(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: List[List[int]]
@alexwal
alexwal / tensorflow-graph-error-handling.py
Last active December 15, 2020 12:03
Example of how to handle errors in a tf.data.Dataset input pipeline
import tensorflow as tf
def create_bad_dataset(create_batches=True):
dataset = tf.data.Dataset.from_tensor_slices([1., 2., 0., 4., 8., 16.])
# Computing `tf.check_numerics(1. / 0.)` will raise an InvalidArgumentError.
if create_batches:
# Demonstrates that error handling works with map_and_batch
dataset = dataset.apply(tf.contrib.data.map_and_batch(
map_func=lambda x: tf.check_numerics(1. / x, 'error'), batch_size=2))
@fmtonakai
fmtonakai / AttributedString.swift
Last active August 6, 2023 21:27
AttributedString with String Interpolation
//
// AttributedString.swift
//
// Created by fm.tonakai on 2019/04/08.
//
import UIKit
public struct AttributedString: ExpressibleByStringLiteral, ExpressibleByStringInterpolation, CustomStringConvertible {
public struct StringInterpolation: StringInterpolationProtocol {
// 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 {