Skip to content

Instantly share code, notes, and snippets.

View TheLarkInn's full-sized avatar
🦀
Getting Rusty

Sean Larkin TheLarkInn

🦀
Getting Rusty
View GitHub Profile
@TheLarkInn
TheLarkInn / outside_event.plugin.ts
Created April 22, 2016 20:24
EventManagerPlugin extension to add to EVENT_MANAGER_PLUGINS for Angular2. Lets you handle clicking outside of target element.
import {DomEventsPlugin} from 'angular2/platform/common_dom';
// Have to pull DOM from src because platform/common_dom returns DOM as null.
// I believe its a TS bug.
import {DOM} from 'angular2/src/platform/dom/dom_adapter';
import {Injectable} from 'angular2/core';
import {noop} from 'angular2/src/facade/lang';
@Injectable()
export class DOMOutsideEventPlugin extends DomEventsPlugin {
eventMap: Object = {
@TheLarkInn
TheLarkInn / rgbFadeLEDTessel.js
Last active April 17, 2016 03:23
Code for fading RGB via color map.
var five = require("johnny-five"),
TesselIO = require("tessel-io"),
board = new five.Board({
io: new TesselIO()
});
// Initial Red color to start with.
// Decent transitions are easier with RGB vs HEX.
var startingColorObject = {
r: 255,
@TheLarkInn
TheLarkInn / bundle.umd.js
Created April 13, 2016 20:44
UMD Wrapped Webpack Lib
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else if(typeof exports === 'object')
exports["fun"] = factory();
else
root["fun"] = factory();
})(this, function() {
@TheLarkInn
TheLarkInn / convertES6StyleAndHTMLImportsToTypeScriptFriendlyRequires.js
Created April 13, 2016 20:18
convertES6StyleAndHTMLImportsToTypeScriptFriendlyRequires.js
module.exports = function convertES6StyleAndHTMLImportsToTypeScriptFriendlyRequires(source) {
this.cacheable && this.cacheable();
var hasES6StyleAndHTMLImportRegex = new RegExp(/import\s+(.+)\s+from\s+([\'|\"].+\.(html|jade|haml|twig|erb|css|scss|less|yaml|sass|styl)[\'\"]);?/, 'g');
var results;
try {
results = source.replace(hasES6StyleAndHTMLImportRegex,
"let $1 = require($2);\n"
);
@TheLarkInn
TheLarkInn / watchEvaluation.js
Created January 28, 2015 14:02
Example of Using $scope.$watch to watch the evaluative value of a function
$scope.$watch(
function () { return obj.hasOwnProperty("choice") },
function (newLocation, oldLocation) {
//Do things here.
}
);
(function () {
var root = angular.element(document.getElementsByTagName('body'));
var watchers = [];
var f = function (element) {
angular.forEach(['$scope', '$isolateScope'], function (scopeProperty) {
if (element.data() && element.data().hasOwnProperty(scopeProperty)) {
angular.forEach(element.data()[scopeProperty].$$watchers, function (watcher) {
watchers.push(watcher);
<script type="text/ng-template" id="one.html">
<div>This is first template</div>
</script>
<script type="text/ng-template" id="two.html">
<div>This is second template</div>
</script>
@TheLarkInn
TheLarkInn / webviewpopup.m
Created February 10, 2014 12:36
Singleton/sorta/sharedInstance
+(WebViewPopup*)sharedWebViewPopup
{
static dispatch_once_t once;
static WebViewPopup* sharedWebViewPopup;
dispatch_once(&once, ^{
sharedWebViewPopup = [[WebViewPopup alloc] init];
});
return sharedWebViewPopup;
}
@TheLarkInn
TheLarkInn / ruby app.rb output
Created January 24, 2014 12:40
ruby app.rb output
sean:tt_project_tracker_api_beta sean$ ruby app.rb
== Sinatra/1.4.4 has taken the stage on 80 for development with backup from Thin
>> Thin web server (v1.5.1 codename Straight Razor)
>> Maximum connections set to 1024
>> Listening on localhost:80, CTRL+C to stop
>> Stopping ...
== Sinatra has ended his set (crowd applauds)
/Users/sean/.rvm/gems/ruby-2.1.0/gems/eventmachine-1.0.3/lib/eventmachine.rb:526:in `start_tcp_server': no acceptor (port is in use or requires root privileges) (RuntimeError)
from /Users/sean/.rvm/gems/ruby-2.1.0/gems/eventmachine-1.0.3/lib/eventmachine.rb:526:in `start_server'
from /Users/sean/.rvm/gems/ruby-2.1.0/gems/thin-1.5.1/lib/thin/backends/tcp_server.rb:16:in `connect'
@TheLarkInn
TheLarkInn / gem env output
Created January 24, 2014 12:37
gem env output
sean:tt_project_tracker_api_beta sean$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 2.2.1
- RUBY VERSION: 2.1.0 (2013-12-25 patchlevel 0) [x86_64-darwin12.0]
- INSTALLATION DIRECTORY: /Users/sean/.rvm/gems/ruby-2.1.0
- RUBY EXECUTABLE: /Users/sean/.rvm/rubies/ruby-2.1.0/bin/ruby
- EXECUTABLE DIRECTORY: /Users/sean/.rvm/gems/ruby-2.1.0/bin
- SPEC CACHE DIRECTORY: /Users/sean/.gem/specs
- RUBYGEMS PLATFORMS:
- ruby