Skip to content

Instantly share code, notes, and snippets.


Chris Nicola chrisnicola

View GitHub Profile
View build_routes.js
export function parseName(path) {
const name = path.toLowerCase()
// Remove starting ./
.replace(/^\.\//, '')
// Parameters
.replace(/\/_(\w+)(\/|\.vue$)/, '/:$1/')
// Remove file extension and 'index'
.replace(/(index)?\.vue$/, '')
// Remove trailing '/'
.replace(/\/$/, '');
chrisnicola / type_compatibility.ts
Created October 27, 2016 21:56
Type inference limitations for Typescript
View type_compatibility.ts
class TypeOne {
public one
private two
private three
class TypeTwo {
public one
chrisnicola / angular.d.ts
Created September 14, 2016 19:51
Fixed Angular type definition
View angular.d.ts
// Type definitions for Angular JS 1.5
// Project:
// Definitions by: Diego Vilar <>
// Definitions:
/// <reference types="jquery" />
declare var angular: angular.IAngularStatic;
// Support for painless dependency injection
chrisnicola / useful_object.rb
Last active September 3, 2016 00:17
A Useful Object Support Module
View useful_object.rb
# Provides a default implementation of the singleton methods of buildable and
# callable classes based on the Useful Object's concept.
module UsefulObject
def self.included(base)
module Builder
def build(*args, **kargs, &block)
chrisnicola / test_helper.rb
Last active August 3, 2016 20:15
Instance Eval'd blocks for ActionDispatch::Integration::Runner#open_session
View test_helper.rb
class ActionDispatch::IntegrationTest
# Override Rails open_session so we can use an instance involved block
# instead of passing the session instance and using it. This allows the block
# to work exactly the same as the regular test.
def open_session(&block)
return super if block.nil? || block.arity > 0
super do |session|
chrisnicola / sorted_test_order.rb
Last active August 3, 2016 11:49
Examples of trying to set test order to be sorted. Note that I'm looking at the order that test files are being run as well. Perhaps that isn't controlled here.
View sorted_test_order.rb
# So far I have tried the following code in test_helper.rb
# Based on documentation here:
class ActiveSupport::TestCase
def test_order
View rails_auto_reloader.rb
require 'auto_reloader'
module RailsAutoReloader
def self.activate
AutoReloader.activate reloadable_paths: ['lib']
class Middleware
def initialize(app)
@app = app
View downgradedAngular2Component.ts
import {Component, Inject, AfterViewInit} from 'angular2/core';
import {upgradeAdapter} from 'upgrade_adapter';
const template = require('./template.html');
// Step 1: Upgrade any Angular 1.x components we depend on
const Dialog = upgradeAdapter.upgradeNg1Component('Dialog');
// Step 2: Import any Angular 2.x components we depend on
import {Calendar} from '../calendar';
View jwt_session_store.rb
require 'active_support/key_generator'
module ActionDispatch
module Session
class JWTStore < AbstractStore
GENERATOR_KEY = "action_dispatch.key_generator".freeze
JWT_SECRET_SALT = "jwt secret salt".freeze
def initialize
View angular.html.slim
| <script>(function(){var w=window;var ic=w.Intercom;if(typeof ic==="function"){ic('reattach_activator');ic('update',intercomSettings);}else{var d=document;var i=function(){i.c(arguments)};i.q=[];i.c=function(args){i.q.push(args)};w.Intercom=i;function l(){var s=d.createElement('script');s.type='text/javascript';s.async=true;
var x=d.getElementsByTagName('script')[0];x.parentNode.insertBefore(s,x);}if(w.attachEvent){w.attachEvent('onload',l);}else{w.addEventListener('load',l,false);}}})()</script>