Skip to content

Instantly share code, notes, and snippets.

View endash's full-sized avatar

Christopher Swasey endash

View GitHub Profile
class Container
def initialize injections
@injections = injections
@resolved = {}
end
def have? token
!get_injection(token).nil?
end
@endash
endash / gist:776938fad064a7fd88de
Last active November 3, 2015 16:53
Angular2 Alpha39 rx async pipe: based on using rxjs 4.0. NOTE: removing the `observeOn` will work if an observable resolves asynchronously, but will break for any observer that resolves synchronously.
/**
* Creates a pipe suitable for a RxJS observable:
*
* @View({
* template: '{{ someObservable | rx}}'
* pipes: [RxPipe]
* })
*
* Originally written by @gdi2290 but updated for 2.0.0.alpha-35 and use AsyncPipe
* (Soon the Angular team will be using RxJS natively and this pipe will be
@endash
endash / gist:a78c838c3ec5b984dedf
Last active September 25, 2015 11:18
Angular 2 tips

Misc

  • Use single quotes ("'foo'") when using a directive to get a string literal

Components

  • When styling a component, the component's root element can be matched with the :host selector

  • Default bindings on the component level, including class names, can be set via the host hash on the @Component annotation:

@endash
endash / __.markdown
Last active October 20, 2015 19:28
Ruby Object Mapper configuration

N.B. This is a strawman proposal This is primarily based on the stand-alone use-case and not part of any framework integration. As such, there are possibly edge or corner cases not taken into account. That said, this is mostly shifting class boundaries around a bit and clarifying semantics, rather than modifying the underlying logic.

The main context here is present-day use of Environment.new, not the global ROM.setup.

Very basic, slapdash first cut at a refactor: https://github.com/endash/rom/tree/rework-env (this really just served to test that the existing code could be re-arranged as intended and still work, not as a genuine attempt at a refactor).

Current issues

Issue 1: We instantiate Environment, but Environment is throw-away. We actually want the Container at the end, in all cases, so that we can get at relations, commands, etc. We even access the Container via Environment#env, so users are encouraged to mentally conflate the two. Environment is, essentially, a sin

@endash
endash / gist:acda517225dc9f4bc9db
Last active September 27, 2019 06:10
Photoshop style gradients in Core Graphics via use of CGShader (with thanks to @jernejstrasner, see his explanation of why your gradients might not look how your designers intended http://jernejstrasner.com/2014/01/09/smooth-gradients-ios.html) ⚠️ see comments for notes
func SineEaseInOutLinearAverage(x: Double) -> Double {
var easeInOutSine = ((cos(M_PI * x) - 1) / -2)
return (easeInOutSine + x) / 2
}
func ShadingFunctionCreate(startColor: NSColor, _ endColor: NSColor, _ slopeFunction: (Double) -> Double) -> (UnsafePointer<CGFloat>, UnsafeMutablePointer<CGFloat>) -> Void {
return { inData, outData in
let q = CGFloat(slopeFunction(Double(inData[0])))
outData[0] = startColor.redComponent + (endColor.redComponent - startColor.redComponent) * q
outData[1] = startColor.greenComponent + (endColor.greenComponent - startColor.greenComponent) * q
@endash
endash / gist:ea75a61c90de30a4bb73
Created June 5, 2015 20:39
Instantiate a view from a nib/xib in Swift, with the current API
extension NSView {
class func instantiateViewFromNib<T>(named nibName: String, inBundle bundle: NSBundle = NSBundle.mainBundle()) -> T? {
var objects : NSArray?
if bundle.loadNibNamed(nibName, owner: nil, topLevelObjects: &objects) {
if let objects = objects {
for object in objects {
if let object = object as? T {
return object
@endash
endash / command.textmate
Last active August 29, 2015 14:15
Quick and dirty multiple file editing in one window for TextMate - Add the command to a bundle (I use source) with: keycombo ⌘S, save document, discard output. Upon saving a file with the 'scratch' extension the script will parse out all the included files and write them to disk IFF they are in the scratch file's directory or a subdirectory thereof
#!/usr/bin/env ruby
require '[..]/scratch_file.rb'
if (file_name = ENV['TM_FILEPATH']) && File.extname(file_name) == ".scratch"
ScratchFile.new(file_name).write!
end
function _main($0,$1) {
$0 = $0|0;
$1 = $1|0;
var $2 = 0, $3 = 0, $4 = 0, $5 = 0, label = 0, sp = 0;
sp = STACKTOP;
_swift_once((_globalinit_33_1BDF70FFC18749BAB495A73B459ED2F0_token9|0),(1|0),(0|0));
HEAP32[__TvOSs7Process5_argcVSs5Int32>>2] = $0;
_swift_once((_globalinit_33_1BDF70FFC18749BAB495A73B459ED2F0_token10|0),(2|0),(0|0));
HEAP32[__TvOSs7Process11_unsafeArgvGVSs20UnsafeMutablePointerGS0_VSs4Int8__>>2] = $1;
$2 = 8;
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Struct</title>
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.15.0.css">
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
Ember.autoComputed = function () {
var args = Array.prototype.slice(arguments);
if (!args.length) return;
var func = args.pop();
if (typeof func !== 'function') return;
var depKeys = args.slice(0, -1);