Skip to content

Instantly share code, notes, and snippets.

View tbuschto's full-sized avatar
🤨

Tim Buschtöns tbuschto

🤨
View GitHub Profile
@tbuschto
tbuschto / SpeedTest.Java
Created November 14, 2011 11:56
Simple RAP performance test
/*******************************************************************************
* Copyright (c) 2011 EclipseSource and others. All rights reserved.
******************************************************************************/
import org.eclipse.rwt.internal.widgets.JSExecutor;
import org.eclipse.rwt.lifecycle.IEntryPoint;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Display;
@tbuschto
tbuschto / Mock.spec
Last active May 22, 2018 21:47
Examples for using mocks in Jasmine Tests
describe( "Mock examples:", function() {
var version = jasmine.version_ ? jasmine.version_.major : parseInt( jasmine.version, 10 );
var spyName = function( spy ) {
if( version === 1 ) {
return spy.identity;
} else {
return spy.and.identity()
}
@tbuschto
tbuschto / console_suggest.js
Last active August 6, 2018 13:35
js console autosuggest
function getSuggestions(input) {
var result = {};
var target = getTarget(input);
if (!target) {
return [];
}
var keys = getAllKeys(target);
var part = getLastPart(input);
for (var i = 0; i < keys.length; i++) {
if (keys[i].toLowerCase().startsWith(part.toLowerCase())) {
console.log('Hello Gist');
@tbuschto
tbuschto / Person.ts
Last active May 15, 2018 10:28
positive decorator
import { ui } from 'tabris';
function positive(prototype: object, property: string) {
const sym = Symbol();
Object.defineProperty(prototype, property, {
enumerable: true,
set(value: number) {
if (value < 0) {
throw new Error('Positive number expected');
}
@tbuschto
tbuschto / Person2.ts
Last active May 15, 2018 10:30
generic type check decorator
import 'reflect-metadata';
import { ui } from 'tabris';
function check(prototype: object, property: string) {
const sym = Symbol();
const constr = Reflect.getMetadata('design:type', prototype, property);
Object.defineProperty(prototype, property, {
enumerable: true,
set(value: any) {
if (!(value instanceof constr) && (typeof value !== constr.name.toLocaleLowerCase())) {
@tbuschto
tbuschto / Person3.ts
Created May 15, 2018 10:23
decorator factory
import { ui } from 'tabris';
function pattern(regEx: RegExp) {
return (prototype: object, property: string) => {
const sym = Symbol();
Object.defineProperty(prototype, property, {
enumerable: true,
set(value: string) {
if (!regEx.test(value)) {
throw new Error(`Invalid ${property} "${value}"`);
@tbuschto
tbuschto / tabris-2-decorators-blog-2-1.tsx
Last active October 18, 2018 09:12
LabeledInput, no databinding
import { ui, Composite } from 'tabris';
import { component, ComponentJSX } from 'tabris-decorators';
// ------------ Component ------------
@component
export default class LabeledInput extends Composite {
private jsxProperties: ComponentJSX<this>;
@tbuschto
tbuschto / tabris-2-decorators-blog-3-1.tsx
Created November 2, 2018 17:21
LabeledInput with data binding
import { Composite, ui, AlertDialog } from 'tabris';
import { bind, component, property, ComponentJSX } from 'tabris-decorators';
// ------------ Component ------------
@component
export default class LabeledInput extends Composite {
@bind('#input.text') public text: string;
@property public labelText: string;
import { Composite, ui, AlertDialog } from 'tabris';
import { bind, component, property, ComponentJSX } from 'tabris-decorators';
// ------------ Component ------------
@component
export default class LabeledInput extends Composite {
@bind('#input.text') public text: string;
@property public labelText: string;