Skip to content

Instantly share code, notes, and snippets.

@kristopherjohnson
kristopherjohnson / contentsOfDirectoryAtPath.swift
Last active November 15, 2017 18:11
Using NSFileManager contentsOfDirectoryAtPath in Swift, with tuple result and CPS interfaces
import Foundation
// Tuple result
// Get contents of directory at specified path, returning (filenames, nil) or (nil, error)
func contentsOfDirectoryAtPath(path: String) -> (filenames: String[]?, error: NSError?) {
var error: NSError? = nil
let fileManager = NSFileManager.defaultManager()
let contents = fileManager.contentsOfDirectoryAtPath(path, error: &error)
@golanlevin
golanlevin / basicspring.pde
Created October 19, 2017 21:03
A Spring in Processing
// A basic spring in Processing, based on:
// Hooke's law: F = -kx
// Newton's law: F = ma
// For more examples, see this lecture:
// http://cmuems.com/2015c/deliverables/deliverables-10/springs/
float restLength;
float vx;
float px;
@keijiro
keijiro / 00_blot4.md
Last active March 17, 2018 09:49
KodeLife fragment shader sketch

gif

@manoloide
manoloide / rectShadows.pde
Created January 9, 2018 07:48
Rect Shadows Particles
ArrayList<Rect> rects;
float mx, my, mm, time;
void setup() {
size(720, 720, P2D);
generate();
}
void draw() {
@russbishop
russbishop / StringExtensions.swift
Last active March 29, 2018 12:45
Swift.String truncate
import Foundation
public enum TruncateMode: Int {
case Head = 0
case Middle = 1
case Tail = 2
}
public extension String {
func nilIfEmpty() -> String? {
/**
* Simple UART module to explore basic HardwareC concepts.
*
* HardwareC is a working name for a new hardware description language. The
* goal is to make FPGAs easier for hobbyists to take advantage of. To achieve
* this goal, some design choices have been made:
*
* 1. Use familiar syntax. C/C++ syntax is borrowed everywhere, no reason to
* reinvent the wheel. Where C/C++ falls short, borrow from Verilog/SystemVerilog.
* 2. Interrop with C/C++. A HardwareC module should be able to be used seamlessly
@gdavis
gdavis / gist:2845766
Created May 31, 2012 19:46
iOS Phone Number Field Formatting With User Entry
#pragma mark - Phone Number Field Formatting
// Adopted from: http://stackoverflow.com/questions/6052966/phone-number-formatting
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
if (textField == self.mobileNumberField || textField == self.homeNumberField || textField == self.workNumberField) {
int length = [self getLength:textField.text];
if(length == 10) {
if(range.length == 0)
@isohedral
isohedral / xi.cpp
Last active December 26, 2018 16:01
C++ value that generates uniform random numbers in [0,1]
// A C++ object that generates uniformly distributed random numbers in [0,1].
// Inspired by the built-in value of the same name in nano ᴊᴀᴍᴍᴇʀ
// (see https://morgan3d.github.io/nano/doc/specification.md.html)
#include <iostream>
#include <random>
static class RandomXi
{
public:
@Queeniebee
Queeniebee / Machine_Learning_Articles_Tutorials_for_Non-ML_Scientists.md
Created April 10, 2016 20:06
List of Machine and Deep Learning Articles Tutorials that Non-ML and/or Non-CS Scientists Can Understand
@keijiro
keijiro / 00_rings.md
Last active December 29, 2018 23:15
KodeLife fragment shader sketch

gif