Skip to content

Instantly share code, notes, and snippets.

View themarcba's full-sized avatar

Marc Backes themarcba

View GitHub Profile
@themarcba
themarcba / vuejs-like-reactive-state.html
Last active February 5, 2024 11:52
Vue.js-like reactive state
<script>
let activeEffect
class Dep {
subscribers = new Set()
depend() {
if (activeEffect) this.subscribers.add(activeEffect)
}
notify() {
this.subscribers.forEach((sub) => sub())
@themarcba
themarcba / vuejs-like-mini-framework.html
Created May 23, 2020 12:24
This is the click counter example for a blog post I wrote about creating your own mini-Vue.js. https://marc.dev/blog/vue-from-scratch-part-5
<style>
* {
user-select: none;
}
body {
margin: 0;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
}
#app {
height: 100vh;
your_collection.find({
your_date_field: {
$gte: ISODate('2020-07-01T00:00:00.000Z'), // From
$lt: ISODate('2020-07-31T23:59:00.000Z'), // Until
},
})
@themarcba
themarcba / README.txt
Last active February 21, 2025 09:53
Vue.js Global - Vue 3 Reactivity Under The Hood
This is an addition to my Vue.js Global 2020 talk about Vue 3 Reactivity.
Some people asked for the slides. You can find them here:
https://marcbackes.com/d8qaLT
const { computed, ref, effect } = require('@vue/reactivity')
let users = ref([])
let onlineUsers = computed(() => {
return users.value.filter((user) => user.status === 'online')
})
effect(() => {
console.log('# of online users changed', onlineUsers.value.length)
})
@themarcba
themarcba / toSarcasm.js
Created February 8, 2021 10:36
Convert any text in "sarcasm text"
const toRandom = c => Math.random() > 0.5 ? c.toUpperCase() : c.toLowerCase()
const toSarcasm = text => text.split('').map(c => toRandom(c)).join('')
console.log(toSarcasm('This is a sarcastic message')); //ThIS Is A SarcAstiC mesSAgE 
if [[ "$*" == "whiskey" || "$*" == "whiskey wednesday" ]]; then
MESSAGE="Whiskey and coding, what can go wrong? Cheers! 🙌"
PREFIX='🥃'
elif [[ "$*" == "beer" || "$*" == "happy hour" ]]; then
MESSAGE='Cheers 🍻'
PREFIX='🍺'
elif [[ "$*" == "frontend" || "$*" == "fe" ]]; then
MESSAGE=''
PREFIX='🎨'
elif [[ "$*" == "backend" || "$*" == "be" ]]; then
#################################################################
# Marc's LAZY code-related aliases (some might require oh-my-zsh)
#################################################################
# For lazy commits
alias c="git commit -m"
# Lazy access to yarn
alias y="yarn"
const sleepSort = arr => {
arr.forEach(n => {
setTimeout(() => console.log(n), n * 1000)
})
}
sleepSort([5, 7, 1, 2])
// Standalone, dependency-free version of rock paper scissors
// Author: Marc Backes (@themarcba)
// Available choices and it's associated values
const choiceMap = { r: 'rock', p: 'paper', s: 'scissors' }
// Request an input from the user
const getInput = query => {
return new Promise((resolve, reject) => {
const readline = require('readline').createInterface({