Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Arvid Kahl arvidkahl

🏠
Working from home
View GitHub Profile
@arvidkahl
arvidkahl / titleize_APA.js
Created Aug 23, 2020
Zero to Published: Automator Workflow to correctly titleize with APA rules ("this is a good title" -> "This Is a Good Title")
View titleize_APA.js
const stopwords = 'a an and at but by for in nor of on or so the to up yet'
const defaults = stopwords.split(' ')
function titleCase1(str, options) {
const opts = options || {}
if (!str) return ''
const stop = opts.stopwords || defaults
const keep = opts.keepSpaces
@arvidkahl
arvidkahl / amazon-wishlist-summation.js
Last active Feb 22, 2019
Sum up the prices in an Amazon Wish List Print View
View amazon-wishlist-summation.js
// Make sure to pass the correct currency symbol, three-letter-name and your locale
(function(currency='$', currencyName='USD', locale='en-US'){return (Math.ceil(100*Array.prototype.slice.call(document.getElementsByTagName('span')).reduce((acc,item,index,src)=>{if(item.innerText.indexOf(currency)>-1){return acc+parseFloat(item.innerText.replace(/,/g,'.').replace(RegExp(currency, "g"),''))}else{return acc}}, 0.0))/100).toLocaleString(locale,{style: 'currency',currency: currencyName,});})("€", "EUR", "de-DE")
View jtw-md.js
Vue.component("tree-view-item", Vue.extend({
name: "tree-view-item",
props: ["data", "max-depth", "current-depth"],
data: function(){
return {
open: this.currentDepth < this.maxDepth
}
},
methods: {
isOpen: function(){
View jtw-chevrons.js
// Modifying the tree-view-item component
// ...
data: function(){
return {
open: true
}
},
methods: {
isOpen: function(){
return this.isRootObject(this.data) || this.open;
@arvidkahl
arvidkahl / jtw-vti-component.css
Last active Feb 18, 2017
jtw-vti-component.js
View jtw-vti-component.css
// Add some CSS for indentation
.tree-view-item {
margin-left: 10px;
}
@arvidkahl
arvidkahl / jtv-transformation.js
Last active Feb 18, 2017
jtv-transformation.js
View jtv-transformation.js
// ... inside the tree-view component
methods: {
// Transformer for the non-Collection types,
// like String, Integer of Float
transformValue: function(valueToTransform, keyForValue){
return {
key: keyForValue,
type: "value",
@arvidkahl
arvidkahl / jtv-empty-component.js
Last active Feb 18, 2017
jtv-empty-component.js
View jtv-empty-component.js
Vue.component("tree-view", Vue.extend({
name: "tree-view",
template: "<div>Tree View</div>",
props: ["data"],
methods: {},
computed: {}
}));
// To be used with <tree-view :data="sampleData"></tree-view>
@arvidkahl
arvidkahl / data.html
Created Feb 17, 2017
JSON Tree View Basic HTML
View data.html
<div class="container" id="vue-root">
<div class="row">
<div class="col-xs-12">
<h1>A JSON Tree View Component in Vue.js</h1>
</div>
</div>
<div class="row">
<div class="col-xs-6">
<pre><code>{{formatJSON(sampleData)}}</code></pre>
@arvidkahl
arvidkahl / eventbus-advanced-events.js
Created Feb 12, 2017
eventbus-advanced-events.js
View eventbus-advanced-events.js
// Emit an Event from a Component using the internal Event Bus
let ComponentWithEventBus = Vue.extend({
mounted: function(){
this.$bus.$emit('status', 'Component mounted')
this.$bus.$on('something', ()=>{
console.log("Something happened");
});
}
});
@arvidkahl
arvidkahl / eventbus-advanced-prototype.js
Created Feb 12, 2017
eventbus-advanced-prototype.js
View eventbus-advanced-prototype.js
// Create a global Event Bus
var EventBus = new Vue()
// Add to Vue properties by exposing a getter for $bus
Object.defineProperties(Vue.prototype, {
$bus: {
get: function () {
return EventBus;
}
}