Skip to content

Instantly share code, notes, and snippets.

View krabello's full-sized avatar

Kevin Rabello krabello

  • Stetson University
  • DeLand, Florida
View GitHub Profile
@krabello
krabello / table_storage_engine.sql
Created September 21, 2018 18:00
Query that shows the storage engines you are using and a number of tables using each storage engine
SELECT engine,
count(*) as TABLES,
concat(round(sum(table_rows)/
1000000,2),'M') rows,
concat(round(sum(data_length)/
(1024*1024*1024),2),'G') DATA,
concat(round(sum(index_length)/
(1024*1024*1024),2),'G') idx,
concat(round(sum(data_length+index_length)/
(1024*1024*1024),2),'G') total_size,
@krabello
krabello / youtube_video_id.php
Created August 17, 2018 12:33
PHP Regex to get youtube video ID
<?php
// Matches
// youtube.com/v/vidid
// youtube.com/vi/vidid
// youtube.com/?v=vidid
// youtube.com/?vi=vidid
// youtube.com/watch?v=vidid
// youtube.com/watch?vi=vidid
// youtu.be/vidid
// youtube.com/embed/vidid
@krabello
krabello / ubuntu-redis-install.sh
Created February 14, 2018 16:49
Configure Redis on Ubuntu
#!/bin/bash
###############################################################################
######################### Install and Configure Redis #########################
###############################################################################
###############################################################################
@krabello
krabello / titlecase.pipe.ts
Created October 19, 2017 04:00
Titlecase Angular Pipe
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'titlecase'
})
export class TitlecasePipe implements PipeTransform {
transform(value: any): any {
if (!value) {
return null;
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'summary'
})
export class SummaryPipe implements PipeTransform {
transform(value: string, limit?: number) {
if (!value) {
return null;
@krabello
krabello / Event-Dispatcher.MD
Last active October 17, 2017 00:45
Event Dispatcher Example

Usage

$event = new SyncDispatcher;

$event->listen('subscribed', function () {
   echo 'handling it 1' . PHP_EOL;
});

$event->listen('un-subscribed', function () {
 echo 'un-subscribed it 1' . PHP_EOL;
@krabello
krabello / countNegatives.php
Created October 15, 2017 07:00
Count Negative Integers in Row/Column-Wise Sorted Matrix
function countNegatives($matrix) {
if (!is_array($matrix)) {
throw new TypeError('The matrix is not an array');
}
//rows
$rows = count($matrix);
// columns
$columns = (array_sum(array_map('count', $matrix)) / $rows);
@krabello
krabello / convert-audio-to-video.sh
Created May 19, 2017 18:46
Converts a Audio file and image to video. In order to be used on youtube
#!/bin/sh
# example line
# 372|"Baby Beluga CD"|Raffi8054BabyBeluga.mp3|http://www.domain.com/img/data/ETA_CD56.jpg
while IFS='|' read field1 field2 field3 field4 || [[ -n "$line" ]]; do
f=$(echo $field2 | tr -d '"' | tr -d ' ' | tr -d '®' | tr -d "'" | tr -d '‘' | tr -d '’' | tr -d '&' | tr -d ',' | tr -d '-')
ffmpeg -loop 1 -i $field4 -i $field3 -c:v libx264 -c:a aac -strict experimental -b:a 192k -shortest ./out/$f.mp4 < /dev/null
done < "$1"
@krabello
krabello / sql
Created April 17, 2017 19:09
Find number of duplicates entries in a column
SELECT COLUMN_NAME, COUNT(*) c FROM table GROUP BY COLUMN_NAME HAVING c > 1;
// only run this script in CLI
(PHP_SAPI !== 'cli' || isset($_SERVER['HTTP_USER_AGENT'])) && die('cli only');