Skip to content

Instantly share code, notes, and snippets.

🏠
Working from home

Alex Onozor alexonozor

Block or report user

Report or block alexonozor

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View froggerGame.js
var Engine = (function(global) {
var doc = global.document,
win = global.window,
canvas = doc.createElement('canvas'),
ctx = canvas.getContext('2d'),
lastTime;
canvas.width = 505;
canvas.height = 606;
doc.body.appendChild(canvas);
@alexonozor
alexonozor / rubycode.rb
Created Apr 22, 2018
Code snippet from my ruby hangman gem.
View rubycode.rb
def menu
option_choice = get_input('')
case option_choice
when "1"
menu_start_game
when "2"
load
when "3"
menu_instruction
when "4", "X", "x", "Q", "q", :quit
View rest.ts
//rest the the entire form values and status.
this.userForm.reset();
//rest the user name and it status.
this.userForm.reset({
userName: ''
});
View patchValue.ts
this.userForm.patchValue({
userName: 'alexonozor'
});
View setValue.ts
this.userForm.setValue({
userName: "AlexOnozor",
firstName: "Alex",
lastName: "Obogbare"
address: { ... } // reduce for brevity
});
View adding_custom_validation.ts
const userForm = new FormGroup({
userName: new FormControl('', [
Validators.required,
Validators.minLength(2),
forbiddenNameValidator(/bob/i) // <-- Here's how you pass in the custom validator.
]),
firstName: new FormControl('', [ Validators.required, Validators.minLength(2)]),
lastName: new FormControl(''),
address: new FormGroup({
street: new FormControl('', Validators.required),
View custom_validation.ts
/** A user name can't match the given regular expression */
export function forbiddenUserNameValidator(nameRe: RegExp): ValidatorFn {
return (control: AbstractControl): {[key: string]: any} => {
const forbidden = nameRe.test(control.value);
return forbidden ? {'forbiddenName': {value: control.value}} : null;
};
}
View gist:05311886e1a32e326046bf26c516863a
const userForm = new FormGroup({
userName: new FormControl('', [ Validators.required, Validators.minLength(4)]),
firstName: new FormControl('', [ Validators.required, Validators.minLength(2)]),
lastName: new FormControl(''),
address: new FormGroup({
street: new FormControl('', Validators.required),
city: new FormControl(''),
zipCode: new FormControl('')
})
});
View inspectformControl.ts
<p>UserName value: {{ userForm.get('userName').value }}</p>
//Get the street of the nested address
<p>Street value: {{ userForm.get('address.street').value}}</p>
View nested_template.html
<div formGroupName="address" class="well well-lg">
<div class="form-group">
<label class="center-block">Street:
<input class="form-control" formControlName="street">
</label>
</div>
<div class="form-group">
<label class="center-block">City:
<input class="form-control" formControlName="city">
</label>
You can’t perform that action at this time.