Skip to content

Instantly share code, notes, and snippets.

View Caffe1neAdd1ct's full-sized avatar
💻
Working on multiple projects

Kevin Andrews Caffe1neAdd1ct

💻
Working on multiple projects
View GitHub Profile
# Setup links
media-ctl -l "'ov2680 1-0036':0 -> 'imx7-mipi-csis.0':0[1]"
media-ctl -l "'imx7-mipi-csis.0':1 -> 'csi_mux':1[1]"
media-ctl -l "'csi_mux':2 -> 'csi':0[1]"
media-ctl -l "'csi':1 -> 'csi capture':0[1]"
# Configure pads for pipeline
media-ctl -V "'ov2680 1-0036':0 [fmt:SBGGR10_1X10/800x600 field:none]"
media-ctl -V "'csi_mux':1 [fmt:SBGGR10_1X10/800x600 field:none]"
media-ctl -V "'csi_mux':2 [fmt:SBGGR10_1X10/800x600 field:none]"
import os
import glob
import csv
import sys
from multiprocessing import Pool, freeze_support
from xlsxwriter.workbook import Workbook
def process_csv_to_xlsx(csvfile):
@Caffe1neAdd1ct
Caffe1neAdd1ct / SessionRejectServiceProvider.php
Created April 15, 2019 10:21
Capturing Laravel Database connection exceptions with Sentry
<?php
namespace Custom\Support;
use \Illuminate\Support\ServiceProvider;
class SessionRejectServiceProvider extends ServiceProvider {
public function register()
{
WITH RECURSIVE materials_list as (
SELECT
1 as n,
produces_names.typeID as produces_id,
produces_names.typeName as produces_name,
materials.quantity as produces_qty,
materials.materialTypeID as material_id,
materials.quantity as material_qty,
material_names.typeName as material_name
FROM invTypeMaterials as materials
@Caffe1neAdd1ct
Caffe1neAdd1ct / cron-timetable-generate.php
Last active October 12, 2018 14:32
Generate a crontab time table showing all the times tasks run at
<?php
require_once './vendor/autoload.php';
/** @todo read straight from the crontab file */
$jobs = [
'task1' => [
'0 6 * * *' => (new \Cron\CronExpression('0 6 * * *')),
'45 7 * * *' => (new \Cron\CronExpression('45 7 * * *')),
'15 8 * * *' => (new \Cron\CronExpression('15 8 * * *')),
@Caffe1neAdd1ct
Caffe1neAdd1ct / str_chunk_min_max.php
Created August 30, 2018 10:34
Splits a string into chunks preferring $min until the end chunk then prefer $max.
<?php
/**
* Splits $str into chunks preferring $min until the end chunk.
* If the remaining chars will fit in a max chunk then max is used.
* @param string $str
* @param integer $min
* @param integer $max
*/
public function str_chunk_min_max($str, $min=1, $max=1)
{
@Caffe1neAdd1ct
Caffe1neAdd1ct / split-by.php
Last active August 29, 2018 07:43
Splitting get parameters by two delimiters
<?php
function getParamSplitBy($param, $delimiter='~', $subDelimiter=':')
{
$paramChunks = array_chunk(preg_split('/('.$delimiter.'|'.$subDelimiter.')/', urldecode($this->getParam($param))), 2);
$keys = array_column($paramChunks, 0);
$unpaddedValues = array_column($paramChunks, 1);
$keyCount = count($keys);
$unpaddedCount = count($unpaddedValues);
$values = ($keyCount > count($unpaddedCount)) ?
@Caffe1neAdd1ct
Caffe1neAdd1ct / from-human-readable.php
Last active August 29, 2018 07:45
Parse a human readable size back to bytes
<?php
function parseSize($size)
{
$unit = preg_replace('/[^bkmgtpezy]/i', '', $size); // Remove the non-unit characters from the size.
$size = preg_replace('/[^0-9\.]/', '', $size); // Remove the non-numeric characters from the size.
if ($unit) {
// Find the position of the unit in the ordered string which is the power of magnitude to multiply a kilobyte by.
return $bytesSize = $size * pow(1024, stripos('bkmgtpezy', $unit[0]));
}
@Caffe1neAdd1ct
Caffe1neAdd1ct / docker.sh
Created August 23, 2018 12:40
Docker commands
# Start service
sudo systemctl start docker
# Build
sudo docker build -t php5-test .
# Run
sudo docker run -itd --entrypoint /bin/sh --name php5-test-app php5-test
# Run with strace available
@Caffe1neAdd1ct
Caffe1neAdd1ct / run.sh
Created July 6, 2018 07:54
Start PHP Inbuilt webserver on current machine IP for sharing/showing projects on the network
## Find adapter name
ip addr show
## Replace enp0s3 with adapter name
"/usr/bin/php56" "-S" "$(ip -f inet addr show enp0s3 | grep -Po 'inet \K[\d.]+'):8000" "-t" "public" "server.php"