Skip to content

Instantly share code, notes, and snippets.

@tmanOC
tmanOC / Car.php
Created October 16, 2020 07:56 — forked from HristoZA/Car.php
Eloquent Blog Car
<?php
class Car extends Model
{
// ...
public function garage()
{
return $this->belongsTo('App\Garage');
image: php:7.3 #The docker image used for each step
pipelines:
default:
- step: &build-test
caches:
- composer
script:
- apt-get update && apt-get install -y unzip
- curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
@tmanOC
tmanOC / bitbucket-pipelines.yml
Created October 16, 2020 07:41
A sample pipeline file
image: php:7.3 #The docker image used for each step
pipelines:
default:
- step: &build-test
caches:
- composer
script:
- apt-get update && apt-get install -y unzip
- curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
@tmanOC
tmanOC / trackExceptionWrapper.js
Created June 23, 2020 06:44
Wrapper for Promise rejections of applicationinsights
appInsights = require("applicationinsights");
let exceptionTrack = appInsights.defaultClient.trackException;
appInsights.defaultClient.trackException = function myExceptionTracker(telemetry) {
let exception = telemetry.exception
//How to test for a Promise
if (Promise.resolve(exception) == exception) {
exception.then(res => {
telemetry.exception = res;
exceptionTrack.call(appInsights.defaultClient, telemetry);
@tmanOC
tmanOC / Output_of_lsof52639
Created April 22, 2020 07:50
lsof output
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
Code\x20H 6181 tielman 52u IPv6 0x570f09f514ea1165 0t0 TCP *:52639 (LISTEN)
@tmanOC
tmanOC / kill_script_by_port.sh
Created April 22, 2020 07:15
Script that works on mac for killing scripts that use a certain port
lsof -i:$1 | awk '{print $2}' | grep -v -e "PID" | sort -u > temp.txt
pids=`cat temp.txt`
rm temp.txt
echo "The ids: $pids"
for id in $pids; do
echo "killing $id";
kill -9 $id;
done
@tmanOC
tmanOC / fullPromiseHandling.js
Created January 27, 2020 06:42
Promises with async await pretty much how I like it
var err, result
[err, result] = await methodThatReturnsAPromise().then(res => [null, res], error => [error]).catch(error => {err = error})
if(err != null) {
handleAnyExceptions(err)
} else if(result != null) {
handleResult(result)
}
@tmanOC
tmanOC / asyncAwaitVersion.js
Created January 27, 2020 06:24
async await version of a method that returns a promise
try {
var result = await methodThatReturnsAPromise()
handleResult(result)
} catch (err) {
handleAnyExceptions(err)
}
@tmanOC
tmanOC / methodThatReturnsAPromise.js
Created January 27, 2020 06:19
Structure of a simple promise handler
methodThatReturnsAPromise().then(result => {
handleResult(result)
}).catch(err => {
handleAnyExceptions(err)
})
@tmanOC
tmanOC / settings.py
Created November 19, 2019 09:15
MySQL 8 connector settings
DATABASES = {
'default': {
'ENGINE': 'mysql.connector.django',
'NAME': '****',
'USER': '****',
'PASSWORD': '****',
'HOST': '****',
'PORT': '****',
'OPTIONS': {
"use_pure": True