Skip to content

Instantly share code, notes, and snippets.

@Fredx87
Fredx87 / sync-control.directive.spec.ts
Created August 22, 2018 17:57
Angular SyncControl directive
import { Component } from '@angular/core';
import { async, TestBed } from '@angular/core/testing';
import { FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms';
import { By } from '@angular/platform-browser';
import { SyncControlDirective } from './sync-control.directive';
class FormGroupHostComponent {
formGroup = new FormGroup({
ctrl: new FormControl('')
});
@Dyljyn
Dyljyn / sync-control.directive.ts
Last active August 2, 2021 12:09
Syncing reactive form controls - Angular (v6)
import {
Directive,
EventEmitter,
InjectFlags,
Injector,
OnDestroy,
OnInit,
Type
} from '@angular/core';
import { AbstractControl, FormControlDirective, FormControlName } from '@angular/forms';
<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:GridSample"
x:Class="GridSample.GridSamplePage">
<ContentPage.Resources>
<ResourceDictionary>
<Style x:Key="headerTablet" TargetType="Label">
<Setter Property="TextColor" Value="White" />
<Setter Property="FontAttributes" Value="Bold" />
<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:GridSample"
x:Class="GridSample.GridSamplePage">
<Grid Padding="20" VerticalOptions="CenterAndExpand">
<Grid.RowDefinitions>
<RowDefinition Height="40" />
<RowDefinition Height="40" />
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Reflection;
namespace MiscUtil.Reflection
{
/// <summary>
/// Non-generic class allowing properties to be copied from one instance
/// to another existing instance of a potentially different type.
@sourcec0de
sourcec0de / js_obj_getter_by_reg.js
Created April 1, 2014 13:32
Select keys from a javascript object using a regular expression. Returns an object containing only the keys that matched the expression in the original object.
var keyMatch = function(o,r){
var c = 0;
var nO = {};
Object.keys(o).forEach(function(k){
c++;
no[k] = k.match(r) ? o[k] : void 0;
});
@tedmiston
tedmiston / nodejs-tcp-example.js
Last active May 20, 2024 11:27
Node.js TCP client and server example
/*
In the node.js intro tutorial (http://nodejs.org/), they show a basic tcp
server, but for some reason omit a client connecting to it. I added an
example at the bottom.
Save the following server in example.js:
*/
var net = require('net');