Skip to content

Instantly share code, notes, and snippets.

Avatar

Cristi Jora cristijora

View GitHub Profile
View Day10 part1.js
const fs = require('fs')
const path = require('path')
const data = fs.readFileSync(path.join(__dirname, 'input.txt'), 'utf-8')
const rows = data.split('\n').filter(r => r !== '')
const matrix = rows.map(row => {
return row.split('').map(cell => {
if (cell === '.') {
return '.'
}
@cristijora
cristijora / collapse.js
Created Aug 26, 2019
Collapse menus Vue Paper Dashboard PRO
View collapse.js
// SidebarPlugin/index.js
const SidebarStore = {
// other code,
linksStore: [],
addSidebarLink(link) {
this.linksStore.push(link)
},
removeSidebarLink(link) {
const index = this.sidebarLinks.indexOf(link)
this.linksStore.splice(index, 1)
View UserForm2.vue
<template>
<div>
<input placeholder="Email" type="email" v-model="form.email"/>
<input placeholder="Name" v-model="form.name"/>
<button @click="onSave">Save</button>
<button @click="onCancel">Save</button>
</div>
</template>
<script>
export default {
View UserEdit.vue
// Parent
<template>
<div>
<span> Email {{user.email}}</span>
<span> Name {{user.name}}</span>
<user-form :user="user" @submit="updateUser"/>
</div>
</template>
<script>
View Dropdown3.vue
// Dropdown.vue (parent)
<template>
<div>
<button @click="showMenu = !showMenu">Click me</button>
<dropdown-menu v-if="showMenu" :items="items" @select-option="onOptionSelected"></dropdown-menu>
</div>
<template>
<script>
export default {
View Dropdown2.vue
// Dropdown.vue (parent)
<template>
<div>
<button @click="showMenu = !showMenu">Click me</button>
<transition name="fade">
<dropdown-menu v-if="showMenu" :items="items"></dropdown-menu>
</dropdown-menu>
</div>
<template>
@cristijora
cristijora / Dropdown.vue
Last active Jul 11, 2019
Dropdown parent access
View Dropdown.vue
// Dropdown.vue (parent)
<template>
<div>
<button @click="showMenu = !showMenu">Click me</button>
<dropdown-menu v-if="showMenu" :items="items"></dropdown-menu>
</div>
<template>
<script>
export default {
@cristijora
cristijora / Product2.vue
Last active Jul 11, 2019
Mutating props
View Product2.vue
<template>
<Product :product="product" @add-to-cart="addProductToCart(product)"></Product>
</template>
<script>
import Product from "./components/Product";
export default {
name: "App",
components: {
@cristijora
cristijora / Product.vue
Last active Jul 11, 2019
Mutate nested props
View Product.vue
<template>
<div class="hello">
<div>Name: {{product.name}}</div>
<div>Price: {{product.price}}</div>
<div>Stock: {{product.stock}}</div>
<button @click="addToCart" :disabled="product.stock <= 0">Add to card</button>
</div>
</template>
View computed-effects-3.js
<price-details :order="order"
@total-change="totalChange">
</price-details>
export default {
// other properties which are not relevant in this example
methods: {
totalChange(grandTotal) {
if (this.isSpecialCustomer) {
this.order = {