Skip to content

Instantly share code, notes, and snippets.

Avatar

Daniel Kelly danielkellyio

View GitHub Profile
View firestoreImport.js
// Imports
const firestoreService = require('firestore-export-import')
const firebaseConfig = require('./src/config/firebase.js')
const serviceAccount = require('./serviceAccount.json')
const fs = require('fs')
const tempFileName = `${__dirname}/data-temp.json`;
// procedure
(async () => {
const fileContents = fs.readFileSync(`${__dirname}/src/data.json`, 'utf8')
@danielkellyio
danielkellyio / DiscussOnTwitter.vue
Created Dec 22, 2020
Discuss on Twitter Vue Component
View DiscussOnTwitter.vue
<template>
<div class="speech-bubble mt-16">
<a
:href="`https://twitter.com/search?q=${url}`"
target="_blank"
class="block no-underline text-blue-500"
>
<font-awesome-icon :icon="['fab', 'twitter']" />
Discuss on Twitter
</a>
@danielkellyio
danielkellyio / WithEmptyRecord.php
Last active May 8, 2020
Trait to get an empty version of an laravel eloquent model
View WithEmptyRecord.php
<?php
use Illuminate\Support\Facades\Schema;
/**
* Trait WithEmptyRecord
* Use to get an empty version of an eloquent model
* (contains all the column names with empty values (or default values specified by the $attributes array) )
*/
trait WithEmptyRecord{
public static function emptyRecord(){
@danielkellyio
danielkellyio / nuxt-js-social-meta-tags.js
Last active Jul 6, 2019
Array of social sharing meta tags for use in Nuxt.js
View nuxt-js-social-meta-tags.js
{
meta: [
{
hid: 'description',
name: 'description',
content: this.description,
},
{
hid: 'og:description',
property: 'og:description',
@danielkellyio
danielkellyio / best-conditional.js
Last active Jun 26, 2019
The best way I've found to to set a variable based on multiple conditions
View best-conditional.js
//In helper file with global helper functions
function switchMap(before_value, map={}, default_value=false){
return Object.keys(map).includes(before_value) ? map[before_value] : default_value;
}
//In code where condition is needed
var friendly_timezone = switchMap(tz_timezone, {
'America/New_York': 'Eastern',
'America/Chicago': 'Central',
'America/Denver': 'Mountain',
@danielkellyio
danielkellyio / just-as-bad-conditional.js
Last active Jun 26, 2019
Another bad way to set a variable based on multiple conditions
View just-as-bad-conditional.js
let friendly_timezone;
switch( tz_timezone ) {
case 'America/New_York':
friendly_timezone = 'Eastern';
break;
case 'America/Chicago':
friendly_timezone = 'Central';
break;
case 'America/Denver':
friendly_timezone = 'Mountain';
@danielkellyio
danielkellyio / bad-conditional.js
Last active Jun 26, 2019
How not to set a single variable based on multiple conditions
View bad-conditional.js
let friendly_timezone;
if( tz_timezone === 'America/New_York' ){
friendly_timezone = 'Eastern';
}else if( tz_timezone === 'America/Chicago'){
friendly_timezone = 'Central';
}else if( tz_timezone === 'America/Denver'){
friendly_timezone = 'Mountain';
}else if( tz_timezone === 'America/Los_Angeles'){
friendly_timezone = 'Pacific';
}else{
@danielkellyio
danielkellyio / DriverConnect.php
Last active Aug 31, 2017
Call Tracking Metrics API Call
View DriverConnect.php
/**
* Make a Call to the Call Metrics API
*
* @author Daniel Kelly
* @return void
*/
private function makeAPICall(){
header('Access-Control-Allow-Origin: *');
$curl = curl_init();
curl_setopt_array($curl, array(