Skip to content

Instantly share code, notes, and snippets.

View azanebrain's full-sized avatar
🤖
Jamming with the console cowboys in cyberspace

AJ Zane azanebrain

🤖
Jamming with the console cowboys in cyberspace
View GitHub Profile
<form [formGroup]="myForm">
<select formControlName="meal">
<option [value]="'dinoburger-special'">Dinoburger Special</option>
<option [value]="'caveman-classic'">Caveman Classic</option>
</select>
<input type="number" formControlName="quantity">
<div formGroupName="extras">
Pickup:
<input type="checkbox" formControlName="pickup">
<select multiple formControlName="sides">
@azanebrain
azanebrain / class-awesome-plugin.php
Last active March 20, 2018 04:58
Adds a link to plugin documentation in the plugin description ~ http://azanebrain.github.io/news/adding-plugin-doc-link
/**
...
* Plugin Name: AJ's Amazing Things Plugin
* Plugin URI: mysite.com
* Description: This plugin does amazing things! Visit the <a href="https://mysite.com/amazing-things/docs" target="_blank">documentation site</a> for usage instructions.
...
*/
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [MyComponentModule],
providers: [
{ provide: SomeSingletonService, useValue: new SomeSingletonServiceMock() }
]
})
.overrideComponent(MyCompComponent, {
set: {
providers: [
export interface MyFormValues {
captcha: number;
password: string;
username: string;
}
export interface MyForm extends FormGroup {
value: MyFormValues;
controls: {
captcha: AbstractControl;
public myForm: FormGroup
constructor(private formBuilder: FormBuilder) { }
ngOnInit() {
this.myForm = this.formBuilder.group({
enabledControl: ['hello'],
disabledControl: [{
value: 'world',
disabled: true
@azanebrain
azanebrain / load-once.ts
Created December 10, 2017 20:08
Defers subsequent calls to an endpoint until the original call has resolved
export class LoadAThing {
private loadingTheThing = null
constructor() {}
/**
* Triggers a call to retrieve something only once
* Subsequent calls will be given the existing promise
*/
public loadThingAsync(): Promise<Environment> {
// Only attempts the call if it is not currently loading
@azanebrain
azanebrain / terminal-bulkchangefiles
Created December 5, 2015 14:59
Bulk change the file extension of all files in a directory
for old in path/to/files/*.txt; do mv $old path/to/files/`basename $old .text`.md; done
@azanebrain
azanebrain / change_user_lang.php
Last active July 15, 2016 15:59
Change the user language depending on the username. This example defaults to Japanese, unless you are me
<?php
/**
* Plugin Name: Change User Language
* Description: Change the language depending on the user
* Version: 0.1
* Author: AJ Zane
* Author URI: http://AJZane.com
* License: GPL2
*/
@azanebrain
azanebrain / multisite-upload-path.php
Created January 27, 2014 20:20
Set a unique upload path for each site on a multisite network (MU Plugin)
<?php
add_filter('upload_dir', 'mu_media_upload_dir');
function mu_media_upload_dir($upload) {
$site_title=str_replace( ' ' , '_' , get_bloginfo('name','raw') );
$upload['path'] = ABSPATH . '/shared/' . $site_title;
switch_to_blog(1);
$upload['url'] = site_url() . '/shared/' . $site_title;
restore_current_blog();
$upload['subdir'] = "";
$upload['basedir'] = $upload['path'];
@azanebrain
azanebrain / hide-wp-plugins
Created January 23, 2014 00:24
Hide plugins and settings panels from the WordPress admin panels to make sure certain users don't deactivate them, or change settings.
add_filter( 'all_plugins', 'hide_plugin_list' );
function hide_plugin_list( $plugins ) {
if ( is_admin() ) {
//Only run this if we're in the Admin panels
unset( $plugins[ 'advanced-custom-fields/acf.php'] );
//Admin only plugins
if ( ! current_user_can( 'administrator' ) ) {
unset( $plugins[ 'better-wp-security/better-wp-security.php'] );