Skip to content

Instantly share code, notes, and snippets.

View iamrommel's full-sized avatar

Rommel C. Manalo iamrommel

View GitHub Profile
@iamrommel
iamrommel / oncollectionchange
Created September 16, 2013 03:15
On collection changed, trap the added item and put some logic and set value for it
partial void Plants_Changed(NotifyCollectionChangedEventArgs e)
{
if (e.Action == NotifyCollectionChangedAction.Add)
{
var addedItem = e.NewItems[0] as HaulerPlant;
if (addedItem == null) return;
addedItem.IsActive = true;
}
@iamrommel
iamrommel / Keyboard Shortcut
Last active September 14, 2019 03:48
Creating a keyboard shortcuts for Lightswitch application
partial void Tickets_Created()
{
this.FindControl("ScreenLayout").ControlAvailable += Tickets_ControlAvailable;
}
void Tickets_ControlAvailable(object sender, Microsoft.LightSwitch.Presentation.ControlAvailableEventArgs e)
{
var screenLayout = e.Control as System.Windows.Controls.Grid;
if (screenLayout == null) return;
@iamrommel
iamrommel / Generic Equality comparer
Created June 28, 2013 16:45
Generic Equality comparer that can be used of linq
using System;
using System.Collections.Generic;
namespace LightSwitchApplication
{
/// <summary>
/// Generic Equality comparer that can be used of linq
/// </summary>
/// <typeparam name="T"></typeparam>
public class EqualityComparer<T> : IEqualityComparer<T>
body
{
background: url(TMMSCM.jpg) center bottom fixed;
background-repeat: no-repeat;
height: 100%;
width: 100%;
background-size: cover;
}
@iamrommel
iamrommel / PremiumComponentFactory
Created June 18, 2013 03:06
Using the Microsoft.LightSwitch.ExportProvider.dll to utilize the MEF in LightSwitch
using System;
using LightSwitchApplication.UserCode.Constants;
using Microsoft.VisualStudio.ExtensibilityHosting;
using System.Linq;
namespace LightSwitchApplication.UserCode.Premium
{
/// <summary>
/// To centralize the method selection use this factory
/// So in the future it will not be cluttered
@iamrommel
iamrommel / promise.all async await
Created January 24, 2019 07:59
Sample of using async/await in loops with promise.all
async function updateAllCustomer(customers) {
const mapsPromises = customers.map(update);
//this will wait until all promise is resolved before going to next line
await Promise.all(mapsPromises);
console.log('Done!');
}
@iamrommel
iamrommel / for...Of
Created January 24, 2019 07:51
Sample of using for ... of loop in javascript to support the async await in sequence order
async function updateAllCustomer(customers) {
for (const customer of customers) {
await update(customer);
}
console.log('Done!');
}
<%
if (s.forceSsl) {
%>
server {
listen 80;
server_name <%-s.publicDomain%>;
# Used by Let's Encrypt
@iamrommel
iamrommel / AddUser
Created November 13, 2018 09:30
Add user using the custom component
import React from 'react'
//import {Mutation} from 'react-apollo'
import {Button, Icon} from 'native-base'
import {Mutation} from './Mutation'
import {ADD_USER, GET_USERS, generateId} from './queries'
const update = (cache, {data: {createUser}}) => {
const {allUsers} = cache.readQuery({query: GET_USERS})
cache.writeQuery({
@iamrommel
iamrommel / Mutation
Created November 13, 2018 09:28
Mutation Component
import React from 'react'
import {Mutation as MutationCore} from 'react-apollo'
import {AsyncStorage} from 'react-native'
// Pull serialized mutations from localstorage
const KEY = '@offlineQueueKey'
const getPending = async () => {
const obj = await AsyncStorage.getItem(KEY)
return JSON.parse(obj) || []