Skip to content

Instantly share code, notes, and snippets.

def record(name, fields=''):
fields = fields.split()
class cls:
def __init__(self, *args):
for key, value in zip(fields, args):
self.__dict__[key] = value
def __repr__(self):
return '%s(%s)' % (name, ', '.join(repr(self.__dict__[key]) for key in fields))
cls.__name__ = name
return cls
@mayoff
mayoff / minimal-metal.swift
Created December 23, 2017 06:43
Hello, Triangle! (MetalKit + Swift 4)
import Cocoa
import MetalKit
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate, MTKViewDelegate {
weak var window: NSWindow!
weak var metalView: MTKView!
let device = MTLCreateSystemDefaultDevice()!
var commandQueue: MTLCommandQueue!
var pipelineState: MTLRenderPipelineState!
@nayato
nayato / Dockerfile
Last active May 8, 2023 13:36
Dockerfile for rust multistage build sample
FROM rustlang/rust:nightly as builder
WORKDIR /app/src
RUN USER=root cargo new --bin ht
COPY Cargo.toml Cargo.lock ./ht/
WORKDIR /app/src/ht
RUN cargo build --release
COPY ./ ./
RUN cargo build --release
//
// MovieRecorder.swift
// RosyWriter
//
// Translated by OOPer in cooperation with shlab.jp, on 2015/1/17.
//
//
//
/*
Copyright (C) 2016 Apple Inc. All Rights Reserved.
//
// Capture.swift
// DemoVIdeoRecordingAndFirebase
//
// Created by Redditor :D on 02/04/2017.
//
import UIKit
import AVKit
import AVFoundation
@KyleGoslan
KyleGoslan / DataSnapsot+Extension.swift
Last active September 28, 2018 11:32
Initilize objects from DataSnapshot that conform to the Codable protocol
import Firebase
extension DataSnapshot {
func toObject<T:Codable>() throws -> T {
var newValue = value as! [String: Any]
newValue["uid"] = key
let data = try! JSONSerialization.data(withJSONObject: newValue, options: .sortedKeys)
return try JSONDecoder().decode(T.self, from: data)
}
@cavedave
cavedave / PrimeFractals
Created October 1, 2017 21:29
Python code to make a logo turtle move. it reads the digits of Smarandache–Wellin numbers if the digit is 0 move a step right. 1 36 degrees to the right of that. etc
#!/usr/bin/python3
import turtle
#the number of digits to use
numDigits = 1000000
changeColorInc = numDigits / 10
colors = iter(["#a6cee3", "#1f78b4", "#b2df8a", "#33a02c", "#fb9a99", "#e31a1c", "#fdbf6f", "#ff7f00", "#cab2d6", "#551A8B"])
#scale = 0.99 1k
#scale = 0.199#10k
@lattner
lattner / TaskConcurrencyManifesto.md
Last active April 16, 2025 12:19
Swift Concurrency Manifesto
@namoshizun
namoshizun / regret_matching.py
Created July 14, 2017 01:03
Use regret matching to play rock-paper-scissors
from __future__ import division
from random import random
import numpy as np
import pandas as pd
'''
Use regret-matching algorithm to play Scissors-Rock-Paper.
'''
class RPS:
import UIKit
import SnapKit
class ViewController: UIViewController {
var scrollView: UIScrollView!
var stackView: UIStackView!
override func viewDidLoad() {
super.viewDidLoad()