Skip to content

Instantly share code, notes, and snippets.

View AlbertoDePena's full-sized avatar

Alberto De Pena AlbertoDePena

  • Crane Worldwide Logistics
  • Willis, TX
View GitHub Profile
@AlbertoDePena
AlbertoDePena / observable-extensions.ts
Last active February 23, 2018 20:51
NativeScript extensions
import { Observable } from "data/observable";
export abstract class ObservableBase extends Observable {
constructor() { super(); }
public getPropertyName<PropertyName extends keyof this>(propertyName: PropertyName) { return propertyName; }
}
export function getProperty<T extends Observable, PropertyName extends keyof T>(observable: T, propertyName: PropertyName) {
import * as Crypto from "crypto-js";
function tryExecute<T>(func: () => T, error: string) {
try { return func(); } catch { throw error; }
}
export function encrypt(key: string, plainText: string): string {
if (!key) { throw "key is required (encrypt)"; }
if (!plainText) { throw "plainText is required (encrypt)"; }
@AlbertoDePena
AlbertoDePena / aurelia-webpack-single-bundle.config.js
Last active April 9, 2018 14:10
Single bundle aurelia webpack
'use strict';
const path = require('path');
const Webpack = require('webpack');
const { AureliaPlugin } = require('aurelia-webpack-plugin');
const resolve = filePath => path.resolve(__dirname, filePath);
module.exports = {
entry: {
import 'toastr/build/toastr.css';
import * as toastr from 'toastr';
toastr.options = {
closeButton: false,
debug: false,
newestOnTop: false,
progressBar: false,
positionClass: 'toast-bottom-full-width',
preventDuplicates: true,
export class EventDispatcher {
public static dispatch(element: Element, eventName: string, args?: any): boolean {
let customEvent: CustomEvent;
if ((window as any).CustomEvent) {
customEvent = new CustomEvent(eventName, {
detail: { args: args },
bubbles: true
});
} else {
@AlbertoDePena
AlbertoDePena / NotifiableTask.cs
Last active June 7, 2018 13:03
Load data / lookups within contructor.
using System;
using System.ComponentModel;
using System.Threading.Tasks;
namespace MyNameSpace
{
public sealed class NotifiableTask<TResult> : INotifyPropertyChanged
{
public NotifiableTask(Task<TResult> task)
{
@AlbertoDePena
AlbertoDePena / toggle-drawer.ts
Created May 3, 2018 20:06
MDL - toggle drawer
import { autoinject, customAttribute } from 'aurelia-framework';
@autoinject()
@customAttribute('dp-toggle-drawer')
export class ToggleDrawerCustomAttribute {
private element: Element;
constructor(element: Element) {
this.element = element;
}
import { autoinject, customAttribute } from 'aurelia-framework';
const MdlControls = {
'button': { type: 'MaterialButton', classes: ['mdl-button', 'mdl-js-button'], rippleEffectSupport: true },
'textfield': { type: 'MaterialTextfield', classes: ['mdl-textfield', 'mdl-js-textfield'], rippleEffectSupport: false },
'layout': { type: 'MaterialLayout', classes: ['mdl-layout', 'mdl-js-layout'], rippleEffectSupport: false },
'menu': { type: 'MaterialMenu', classes: ['mdl-menu', 'mdl-js-menu'], rippleEffectSupport: true },
'data-table': { type: 'MaterialDataTable', classes: ['mdl-data-table', 'mdl-js-data-table'], rippleEffectSupport: true },
'tabs': { type: 'MaterialTabs', classes: ['mdl-tabs', 'mdl-js-tabs'], rippleEffectSupport: true },
'slider': { type: 'MaterialSlider', classes: ['mdl-slider', 'mdl-js-slider'], rippleEffectSupport: false },
public class DelegateCommand<T> : ICommand
{
private readonly Predicate<T> _canExecute;
private readonly Action<T> _execute;
public DelegateCommand(Action<T> execute) : this(execute, x => true)
{ }
public DelegateCommand(Action<T> execute, Predicate<T> canExecute)
using System.ComponentModel;
namespace ViewModels
{
public interface IObservableObject : INotifyPropertyChanged
{
void RaisePropertyChanged(string propertyName);
}
public class ObservableObject : IObservableObject