Skip to content

Instantly share code, notes, and snippets.

View achakravarty's full-sized avatar

Abhimanyu Chakravarty achakravarty

View GitHub Profile
@achakravarty
achakravarty / Inferable.ts
Last active April 10, 2019 05:13
Simple type inference for properties of an object
type Inferable<T, K extends keyof T> = T[K] extends Function ? T[K] : never;
function asInferable<T, K extends keyof T>(_: T, key: K): (fn: Inferable<T, K>) => void {
return function(fn: Inferable<T, K>) {
console.log(fn("world"));
};
}
class Foo {
bar(str: string): string {
@achakravarty
achakravarty / dateTest.spec.js
Created May 4, 2017 14:55
Testing Date with sinon using fakeTimers and spies
const sinon = require('sinon');
const { expect } = require('chai');
describe('Timer', () => {
it('should verify Date constructor called', () => {
let dateSpy = sinon.spy(global, 'Date');
const date = new Date();
expect(dateSpy.calledWithNew()).to.be.true;
dateSpy.restore();
});
@achakravarty
achakravarty / app.js
Created November 11, 2013 05:18
Sample code for demonstrating jQuery validations with Ember.js
var App = Ember.Application.create();
App.Router.map(function(){
this.resource('user');
});
App.UserController = Ember.ObjectController.extend(Ember.Evented, {
actions: {
submit: function(){
var validation = {isValid: false};