Skip to content

Instantly share code, notes, and snippets.

@dansalias
dansalias / MaterialInput.vue
Created October 2, 2018 09:59
Material-style (animated placeholder label) text input component in Vue.js
<template>
<div class="input-wrapper">
<input :type="type" :class="{ 'has-content': value.length }" v-model="value">
<div class="input-label">{{ label }}</div>
</div>
</template>
<script>
export default {
name: 'Input',
@dansalias
dansalias / capitalise.js
Last active November 18, 2019 21:29
Lambda Testing Example - capitalise.js
const changeCase = require('change-case');
exports.handler = async function(event) {
const result = { success: false, name: '' };
if(event.name) {
result.name = changeCase.titleCase(event.name);
result.success = true;
}
return result;
}
@dansalias
dansalias / capitalise.spec.js
Last active November 18, 2019 21:28
Lambda Testing Example - capitalise.spec.js
describe('capitalise lambda', () => {
it('should capitalise the first letter of every word', () => {
const handler = require('capitalise.js').handler;
const result = handler({name: 'dan salias'});
expect(result).toStrictEqual({name: 'Dan Salias'});
});
});
@dansalias
dansalias / package.json
Created November 15, 2019 10:03
Lambda Testing Example - package.json
{
...
"scripts": {
"test": "nvm exec 10.16.3 npx jest",
...
},
...
"devDependencies": {
...
"jest": "^24.9.0",
@dansalias
dansalias / node-switch.sh
Created December 9, 2019 18:25
Switch node versions without nvm
#!/bin/bash
system=linux-x64
directory=$HOME/.node-versions
# create directory
prepare() {
mkdir -p $directory
}
# install specified version
@dansalias
dansalias / .zshrc
Created December 9, 2019 19:14
Switch node versions without nvm
# node-switch alias
alias ns=$HOME/scripts/node-switch.sh
# switch node version based on .nvmrc
default_node_version=12.13.1
chpwd() {
if [[ -f .nvmrc && -r .nvmrc ]]; then
ns switch "$(< .nvmrc)"
elif [[ $(node --version) != v$default_node_version ]]; then
ns switch $default_node_version
@dansalias
dansalias / htmlElementWithAttributes.js
Created January 14, 2020 15:15
Create DOM elements with attributes.
const myScript = Object.assign(document.createElement('script'), {
src: '/some-script.js',
type: 'text/javascript',
async: true,
});
document.head.appendChild(myScript);
@dansalias
dansalias / package.json
Last active July 3, 2022 15:00
Squash npm version bumps into previous commit
{
"scripts": {
"postversion": "git reset --soft HEAD~1 && git commit --amend -C HEAD",
...
}
...
}
}
@dansalias
dansalias / invalidate-cf.sh
Last active October 6, 2023 11:32
Invalidate an AWS CloudFront Distribution by domain name
#!/bin/bash
# get the CloudFront Id
CF_DISTRIBUTION_ID=$(aws cloudfront list-distributions \
--query "DistributionList.Items[?contains(Aliases.Items[0], "example.com")] | [0].Id" \
--output text
)
# invalidate all paths
aws cloudfront create-invalidation --distribution-id ${CF_DISTRIBUTION_ID} --paths "/*"
@dansalias
dansalias / CMCIMPORT.gs
Last active October 8, 2021 13:15
Import coinmarketcap.com crypto prices into Google Sheets
/**
* - Create a coinmarketcap.com account and paste your API key below.
* - In Google Sheets go to Tools -> Script editor and paste this code in a new CMCIMPORT.gs script file
* - Use the function in your sheet, e.g. =CMCIMPORT("ADA")
*/
function CMCIMPORT(symbol) {
const cache = CacheService.getDocumentCache()
if (cache.get('prices') == null) {
const response = UrlFetchApp.fetch('https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest?start=1&limit=500&convert=USD',{
headers: {