Skip to content

Instantly share code, notes, and snippets.

View danielkellyio's full-sized avatar

Daniel Kelly danielkellyio

View GitHub Profile
@danielkellyio
danielkellyio / WithEmptyRecord.php
Last active May 8, 2020 18:03
Trait to get an empty version of an laravel eloquent model
<?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 / DiscussOnTwitter.vue
Created December 22, 2020 17:07
Discuss on Twitter Vue Component
<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>
// 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 / gist:08ce944cff5e9fec67e04962174071ae
Created June 3, 2021 19:24
Vue School Link Placement Screenshots
See images in comments below
@danielkellyio
danielkellyio / gist:b9bb9a3ed5754c01dbf5952e41e4f4a3
Created June 15, 2021 14:38
Vue School Links Screenshots
see screenshots in comment below
see screenshots in comments below
@danielkellyio
danielkellyio / string.js
Created July 2, 2021 02:25
String Helpers Examples
export const ucFirst = (string)=>{
if (typeof string !== 'string') return ''
return string.charAt(0).toUpperCase() + string.slice(1)
}
export const ucWords = (string) =>{
if (typeof string !== 'string') return ''
return string.split(' ').map(word => ucFirst(word)).join(' ')
}
@danielkellyio
danielkellyio / string.test.js
Last active July 2, 2021 02:34
String Test Example
import {ucFirst, snakeCase, camelCase, sentenceCase, ucWords, titleCase, nestedFromDot} from '~/helper/string'
describe('string helper functions', ()=>{
test('ucFirst capitalizes the first letter in a string', ()=>{
expect(ucFirst('hello world')).toBe('Hello world')
})
test('ucWords capitalizes the first letter in each word of a string', ()=>{
expect(ucWords('hello world')).toBe('Hello World')
})
@danielkellyio
danielkellyio / Cache.js
Created July 2, 2021 02:31
Cache Class Helper Example
/**
* docs: /docs/cache.md
*/
import LZUTF8 from 'lzutf8'
window.LZUTF8 = LZUTF8
let cache = { 'default': {} }
try{
cache = JSON.parse( LZUTF8.decompress(localStorage.getItem('app_cache'), {inputEncoding: 'StorageBinaryString'}) )
Object.keys(cache).forEach(groupName =>{
@danielkellyio
danielkellyio / Cache.test.js
Created July 2, 2021 02:33
Cache Class Helper Unit Test Example
import Cache from '~/helper/Cache'
describe('Cache class', ()=>{
test('get method retrieves items from the cache', ()=>{
const cache = new Cache()
cache.put('hello', 'world')
expect(cache.get('hello')).toBe('world')
})
test('put method adds items to the cache', ()=>{
(new Cache).put('hello', 'world')