Skip to content

Instantly share code, notes, and snippets.

View aleclarson's full-sized avatar

Alec Larson aleclarson

View GitHub Profile
@aleclarson
aleclarson / ObjectCasting.swift
Last active August 29, 2015 14:14
Casting to and from Any, AnyObject, and NSObject
// https://gist.github.com/aleclarson/e076f1fa0fc4ebedc9a1
//
// Check out this link for more information.
// https://gist.github.com/aleclarson/e076f1fa0fc4ebedc9a1#comment-1379921
import Foundation
// MARK: Type checking
@aleclarson
aleclarson / index.coffee
Created April 6, 2015 04:57
getCommonDirectory of two paths
Path = require "path"
getDirectories = (path) ->
dirs = []
path = Path.resolve path unless Path.isAbsolute path
dirs.push Path.basename path if Path.extname(path) is ""
loop
dir = Path.dirname path
break if dir is "/"
dirs.push dir.slice dir.lastIndexOf("/") + 1
@aleclarson
aleclarson / coffee-module.bash
Last active August 29, 2015 14:18
Create a CoffeeScript module with a single command!
#!/bin/bash
# coffee-module <module-name>
coffee-module () {
if [ -d "$@" ]; then
echo "Directory named '$@' already exists!"
return
fi
@aleclarson
aleclarson / README.md
Created June 14, 2015 09:57
applyToNew(constructor, args)

usage

MyConstructor = ->
  this.args = arguments
  this

obj = applyToNew MyConstructor, [1, 2, 3]

obj.args # [ 1, 2, 3 ]
TimerMixin = require "react-timer-mixin"
combine = require "combine"
steal = require "steal"
hook = require "hook"
module.exports = (descriptor) ->
methods = combine {}, TimerMixin
initialPosition = 0
module.exports =
decay =
equation: "react"
dynamicsThreshold: 0.01
require "../../../lotus-require"
NamedFunction = require "named-function"
WeakMap = require "weak-map"
Namespace = module.exports = NamedFunction "Namespace", ->
return new Namespace unless @ instanceof Namespace
@cache = WeakMap()
@
@aleclarson
aleclarson / countDigits.coffee
Created March 17, 2016 00:12
Count the number of digits (before the decimal) in a number
module.exports = (n) ->
n = Math.abs n
return 1 if n < 1
count = 0
while n >= 1
count += 1
n /= 10
count
@aleclarson
aleclarson / OuterBorder.coffee
Created November 14, 2016 19:41
OuterBorder (for React Native)
{Component, Device} = require "modx"
hexToRgb = require "hex-rgb"
type = Component "OuterBorder"
type.defineProps
style: Style
child: Element
@aleclarson
aleclarson / ObjectIdentifier.swift
Last active December 9, 2016 01:37
Convenience functions for ObjectIdentifier hashes
/// Generate a unique identifier for an AnyObject.
/// 2nd slowest. Converts to String.
public func obid (object: AnyObject) -> String {
return "\(obid(object) as Int)"
}
/// Generate a unique identifier for an AnyObject.
/// Fastest. Every other function relies on this one.
public func obid (object: AnyObject) -> Int {