Skip to content

Instantly share code, notes, and snippets.

enum Test {
one,
two,
three
}
interface EnumIterator<TEnum extends number> {
iterate(myEnum: TEnum, callback: (value: number, name: string) => void): void;
}
var chunkSize = 5, batchMod = Math.pow(10, chunkSize);
function getChunks(num) {
var chunks = [],
count = 0;
while (true) {
var length = chunkSize,
shouldBreak = false;
var startIndex = num.length - chunkSize * ++count;
if (startIndex < 0) {
@adamcarr
adamcarr / annotest-example.ts
Created June 7, 2015 22:56
Simple example of an annotest unit test using decorators
/// <reference path="../typings/tsd.d.ts" />
import * as assert from 'assert';
import annotest from '../index';
import IPerson from './IPerson';
@annotest.ModuleDecorator('Person tests', {'./IsEighteenOrOlder': {default:(age: number) => age > 19}})
class MyCustomTest {
@annotest.TestMethodDecorator('Testing person constructor')
@adamcarr
adamcarr / designer.html
Last active August 29, 2015 14:09
designer
<link rel="import" href="../core-scaffold/core-scaffold.html">
<link rel="import" href="../core-header-panel/core-header-panel.html">
<link rel="import" href="../core-menu/core-menu.html">
<link rel="import" href="../core-item/core-item.html">
<link rel="import" href="../core-icon-button/core-icon-button.html">
<link rel="import" href="../core-toolbar/core-toolbar.html">
<link rel="import" href="../core-menu/core-submenu.html">
<link rel="import" href="../chart-js/chart-js.html">
<polymer-element name="my-element">
@adamcarr
adamcarr / gist:7875740
Created December 9, 2013 16:55
Activity Logging Output
Beginning activity, Data: [{"name":"PAGE_START","parent":null,"isComplete":false,"id":"55c5dfdc-1c6f-3ebb-c1ce-895322e4e83d"}], ActivityId: [null], ParentActivityId: [null] testApp.js:88
Beginning activity, Data: [{"name":"testController.INITIALIZE","parent":{"name":"PAGE_START","parent":null,"isComplete":false,"id":"55c5dfdc-1c6f-3ebb-c1ce-895322e4e83d"},"isComplete":false,"id":"a516d955-0105-3e36-b69d-bf1316bfd2d3"}], ActivityId: [55c5dfdc], ParentActivityId: [null] testApp.js:88
Setting $scope.currentDateTime to the current time: [Mon Dec 09 2013 08:52:18 GMT-0800 (PST)], Data: [undefined], ActivityId: [a516d955], ParentActivityId: [55c5dfdc] testApp.js:88
Completing activity, Data: [{"activityName":"testController.INITIALIZE"}], ActivityId: [55c5dfdc], ParentActivityId: [null] testApp.js:88
logging something while in a timeout which should be outside initialize scope, Data: [undefined], ActivityId: [55c5dfdc], ParentActivityId: [null] testApp.js:88
Appending to activity, Data: [{"name":"testControll
@adamcarr
adamcarr / gist:7875676
Created December 9, 2013 16:51
Activity Logging Example
var initializeActivity = loggerService.startActivity(activities.testController.INITIALIZE);
$scope.currentDateTime = new Date();
loggerService.log('Setting $scope.currentDateTime to the current time: [' + $scope.currentDateTime + ']');
loggerService.endActivity(activities.testController.INITIALIZE);
$timeout(function () {
loggerService.log('logging something while in a timeout which should be outside initialize scope');
});
@adamcarr
adamcarr / gist:2783793
Created May 24, 2012 19:45
Exception vs Out Parameter Benchmark
using System;
using System.Collections.Generic;
using System.Text;
namespace ExceptionVsOutParamBenchmark
{
class Program
{
static void Main(string[] args)
{
@adamcarr
adamcarr / ruby_intersect_arrays.rb
Created October 30, 2011 04:00
ruby intersection of arrays
def intersect_arrays(arrays)
result = []
init = false
massaged_array = arrays.compact.uniq || []
massaged_array.each do |a|
unless init
result = a
init = true
else
result = result & a
@adamcarr
adamcarr / ubuntu_rvm_rails.sh
Created June 7, 2011 02:02
Ubuntu RVM Rails
#!/bin/bash
echo "Installing dependencies"
sudo apt-get install ruby curl bison build-essential autoconf zlib1g-dev libssl-dev libxml2-dev libreadline6-dev git-core subversion sqlite3
echo "Installing RVM"
bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)
echo "Configuring RVM"
@adamcarr
adamcarr / subdomain_session_store.rb
Created June 2, 2011 03:45
Fix for getting session store cookies to work across subdomains
#Rails.application.config.session_store :cookie_store, :key => '_bloggit_session', :domain => :all
Rails.application.config.session_store :cookie_store, :key => '_bloggit_session', :domain => '.example.com'