Skip to content

Instantly share code, notes, and snippets.

View AndrewAllison's full-sized avatar

Andy Allison AndrewAllison

View GitHub Profile
@AndrewAllison
AndrewAllison / SearchType.component,html
Created December 4, 2017 08:30
Using reactive forms in a nice simple manner
<div [formGroup]="searchTermFormGroup">
<mat-form-field>
<input matInput formControlName="searchValueControl">
<mat-error>
Search term
<strong>required</strong>
</mat-error>
</mat-form-field>
</div>
@AndrewAllison
AndrewAllison / main.ts
Last active December 2, 2017 10:19
RXJS using Take while
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
// Common rxjs operators
import 'rxjs/add/operator/takeWhile';
if (environment.production) {
@AndrewAllison
AndrewAllison / pin.ps1
Created November 3, 2017 07:19
Useful ping
Test-NetConnection 35.197.254.126 -port 11211
@AndrewAllison
AndrewAllison / clean.ps1
Last active November 3, 2017 06:23
Clean AWS stuffs
$array = aws s3api list-buckets --query "Buckets[].Name" | Where { $_ -like "*.tb-*" -and $_ -notlike "*.tb-nav*" }
"Found $array.Length buckets"
$count = 0
for ($i=0; $i -lt $array.Length; $i++) {
$count = $i + 1
$bucket = $array[$i] -replace '"' -replace ','
$bucket = $bucket.Trim()
<div fxLayout="column">
<div fxLayout="row">
<div fxFlex fxLayout="column">
<!-- GHOST ELEMENT -
Similar to Chosen with hidden selects....
We use this as a container becasue the changes don't bind well to a textarea it doesn't fire the correc caret event to track length.. !!!!-->
<div style="display:none" class="emoji-content-editable textarea" (emojiPickerCaretEmitter)="handleCurrentCaret($event)"
(input)="content = $event.target.textContent" [textContent]="content" contenteditable="true">
</div>
<md-input-container *ngIf="type === 'standard'" class="full-width" floatPlaceholder="never">
@AndrewAllison
AndrewAllison / basics.js
Created July 6, 2017 07:03
Javascript snippits
// Find the shortest word in an arra of words
// Example "Some so WOrds Will Be Longer" would return 2
function findShort(s){
return Math.min.apply(null, s.split(' ').map(w => w.length));
}
@AndrewAllison
AndrewAllison / repeat.ts
Created June 15, 2017 08:13
RxJs for retrying to see if a value has changed over a period
const state = Observable.timer(1000) // every second
.map(() => this.loaded)
.repeat(8) // retry 8 times
.retry();
state.subscribe((res) => {
// this is the main body of the retry
console.log('Result: ', res) // will out put false 8 times for the loaded value.
}, (err) => { }, () => {
if (this.loaded === false) {
this.errorLoading = true; // If it hasn't loaded in 8 secs it ain't gonna ;)
@AndrewAllison
AndrewAllison / deploy.sh
Created May 19, 2017 07:13
Deploy on Codeship
npm install -g @angular/cli
npm install
ng build --environment=prod
mkdir deploy deploy/`git rev-parse HEAD` commits
cp dist/ deploy/`git rev-parse HEAD` -rf
git rev-parse HEAD > commits/`git rev-parse HEAD`
@AndrewAllison
AndrewAllison / javascript.json
Created April 21, 2017 06:04
Vscode Snippets
{
"Print to console": {
"prefix": "log",
"body": [
"console.log('$1');",
"$2"
],
"description": "Log output to console"
},
"For Loop": {
@AndrewAllison
AndrewAllison / lists.sql
Created April 15, 2017 18:26
Lists Changes
ALTER TABLE `talkbe_production`.`lists`
ADD COLUMN `promoted` TINYINT(1) NULL AFTER `temp`,
ADD COLUMN `order` INT(11) NULL AFTER `promoted`;