Skip to content

Instantly share code, notes, and snippets.

@fillup
fillup / gii-create-base-and-extending-classes.md
Last active August 29, 2015 14:02
Proposal for Yii2 Gii Model generation to create base class and extending class

Gii provides a very easy way to generate Model classes from a database schema. However, model classes often need to be modified in order to add functionality. Once the model has been modified, you can no longer use Gii to create new versions of the model class when the database schema changes.

As a better practice one should use Gii to generate a base class, then create an extending class that is modified as needed. This allows Gii to regenerate the Base class as often as needed whenever the table schema changes.

Ideally Gii would provide an option to automatically generate both the Base class file and the Extending class file if it does not already exist. I think it would be great if part of the Gii configuration had an option to provide a "Base Class Suffix" that would be appended to the base class name and file name and then the extending class file would be created and extend it properly.

For example, for a “user” database table, Gii could create a class/file named UserBase. If there is no User class/f

@fillup
fillup / yii2-migration-regenerate-base-classes.md
Last active August 29, 2015 14:02
Proposal for Yii2 database migration script to automatically regenerate model classes

Yii has some great features for simplifying and automating portions of development. Two key areas are...

  • Gii generating model classes based on table schemas
  • Using the yiic migrate command to manage schema changes

I am proposing two enhancements to these areas. For Gii model generation, I suggest that it create separate Base and extending classes (https://gist.github.com/fillup/5cdba5990c6576bbbfb0). In this Gist I propose that the migration support is enhanced to add a parameter for automatically regenerating the base classes for affected (or all) tables.

My ideal workflow would be:

  1. ./yiic migrate create create_table_user // migration for creating a table named 'user'
@fillup
fillup / cleanheaders.sh
Created June 30, 2014 12:59
Script to clean up old kernel headers to free up space on /boot on Ubuntu
#!/bin/bash
sudo apt-get purge $(dpkg -l linux-{image,headers}-"[0-9]*" | awk '/ii/{print $2}' | grep -ve "$(uname -r | sed -r 's/-[a-z]+//')")
@fillup
fillup / BatchDeleteFilepickerFiles.md
Last active August 29, 2015 14:05
Manually batch delete files from Filepicker.io account.

I recently needed to batch delete all of the files in my filepicker.io account, but there is no way to do that through their UI or APIs, at least that I could find (unless you still have all their IDs in your own database in which this is not necessary). In their Developer Console I can browse the files in the account and delete each one individually, but that would take an extremely long time for hundreds or thousands of files.

My solution is still a bit slow and manual, but much much faster than clicking each one individually. This is a simple javascript snippet that can be run in your browser developer console on the Browse Files page when logged into Filepicker.io

$('.filelink').each(function(index){
   var url = window.location+'/remove/';
   var handle = $(this).attr('data-handle');
   $.post(url,{handle: handle}, function(response){
 console.log(handle);
@fillup
fillup / google-example.php
Last active November 30, 2022 08:08
Example of using Google Admin SDK Directory API to get an individual or list of users.
<?php
// Updated 2018-01-24 to work with google/apiclient:^2.0
/*
* Easiest to use composer to install google-api-php-client and generate autoloader
* If you dont want to use composer you can manually include any needed files
*/
include_once 'vendor/autoload.php';
/*
* Email address for admin user that should be used to perform API actions
<?php
use Nexmo\Developer;
use Nexmo\Insight;
use Nexmo\Sms;
use Nexmo\Verify;
use Nexmo\Voice;
/*
* Get an SMS client object
@fillup
fillup / issue-notes.md
Created March 30, 2017 17:49
Issue with Terraform aws_ecs_service when using placement_strategy

Below is the series of Terraform commands run and the relevant snippets of output from each:

resource "aws_ecs_service" "service" {
   name = "${var.service_name}"
   cluster = "${var.cluster_id}"
   desired_count = "${var.desired_count}"
   iam_role = "${aws_iam_role.ecsServiceRole.arn}"
   depends_on = ["aws_iam_role_policy.ecsServiceRolePolicy", "aws_alb_listener.https"]
@fillup
fillup / terraform-destroy.log
Created April 20, 2017 15:17
debug log output from terraform destroy
2017/04/20 10:13:24 [INFO] Terraform version: 0.9.3
2017/04/20 10:13:24 [INFO] Go runtime version: go1.8.1
2017/04/20 10:13:24 [INFO] CLI args: []string{"/usr/local/Cellar/terraform/0.9.3/bin/terraform", "destroy", "-force"}
2017/04/20 10:13:24 [DEBUG] Detected home directory from env var: /Users/shipley
2017/04/20 10:13:24 [DEBUG] Detected home directory from env var: /Users/shipley
2017/04/20 10:13:24 [DEBUG] Attempting to open CLI config file: /Users/shipley/.terraformrc
2017/04/20 10:13:24 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2017/04/20 10:13:24 [INFO] CLI command args: []string{"destroy", "-force"}
2017/04/20 10:13:24 [DEBUG] Detected home directory from env var: /Users/shipley
2017/04/20 10:13:24 [DEBUG] command: loading backend config file: /Users/shipley/code/terraform-test
Error applying plan:
1 error(s) occurred:
* module.cluster.module.asg.aws_autoscaling_group.asg: aws_autoscaling_group.asg: diffs didn't match during apply. This is a bug with Terraform and should be reported as a GitHub Issue.
Please include the following information in your report:
Terraform Version: 0.10.0
Resource ID: aws_autoscaling_group.asg
#!/usr/bin/env bash
echo "it works"