Skip to content

Instantly share code, notes, and snippets.

View pichsenmeister's full-sized avatar
one sparkle at a time

David Pichsenmeister pichsenmeister

one sparkle at a time
View GitHub Profile
@pichsenmeister
pichsenmeister / reflection-instantiation.scala
Last active February 16, 2017 03:04
scala reflection: create instance
def getObjectInstance(clsName: String): ModuleMirror = {
val mirror = runtimeMirror(getClass.getClassLoader)
val module = mirror.staticModule(clsName)
mirror.reflectModule(module).instance
}
def getClassInstance(clsName: String): Any = {
val mirror = runtimeMirror(getClass.getClassLoader)
val cls = mirror.classSymbol(Class.forName(clsName))
val module = cls.companionSymbol.asModule
@pichsenmeister
pichsenmeister / reflection-import.scala
Last active December 20, 2015 17:18
scala reflection: import
import scala.reflect.runtime.universe._
@pichsenmeister
pichsenmeister / reflection-invoking.scala
Created August 6, 2013 19:25
scala reflection: invoking a method
def invokeMethod(param: String) = {
val im =mirror.reflect(getObjectInstance("models.entities.User"))
val method = im.symbol.typeSignature.member(newTermName("findByUsername")).asMethod
im.reflectMethod(method)(param)
}
@pichsenmeister
pichsenmeister / reflection-object.scala
Created August 6, 2013 19:28
scala reflection: example object
package models.entities
object User {
def findByUsername(username: String) = {
// database or whatever magic is done here ;)
}
}
@pichsenmeister
pichsenmeister / index.html
Last active December 21, 2015 03:48
typescript & angular default imports
<!DOCTYPE html>
<html lang="en" ng-app="showcase" data-framework="typescript">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
</head>
<body>
<ul class="menu">
<li><a href="#/first">first</a></li>
@pichsenmeister
pichsenmeister / import.ts
Last active December 21, 2015 03:48
angularJS and typescript import
/// <reference path='../_all.ts' />
@pichsenmeister
pichsenmeister / includes.ts
Created August 15, 2013 20:50
angularJS and typescript includes
/// <reference path='libs/angular.d.ts' />
/// <reference path='models/MyModel.ts' />
/// <reference path='controllers/FirstCtrl.ts' />+
/// <reference path='controllers/SecCtrl.ts' />
/// <reference path='app.ts' />
@pichsenmeister
pichsenmeister / app.js
Last active December 21, 2015 03:48
angularJS and typescript app.js
/// <reference path='_all.ts' />
module angularTs {
'use strict';
var showcase = angular.module('showcase', []);
showcase.controller('firstCtrl', FirstCtrl.prototype.injection());
showcase.controller('secCtrl', SecCtrl.prototype.injection());
@pichsenmeister
pichsenmeister / model.js
Last active December 21, 2015 03:48
angularJS and typescript model
/// <reference path='../_all.ts' />
module angularTs {
'use strict';
export class Coffee {
constructor(
public milk: Milk,
public size: number,
public name: string){}
@pichsenmeister
pichsenmeister / ctrl.js
Last active December 21, 2015 03:49
angularJS and typescript controller
/// <reference path='../_all.ts' />
module angularTs {
'use strict';
export interface IFirstScope extends ng.IScope {
vm: FirstCtrl;
}
export class FirstCtrl {