Skip to content

Instantly share code, notes, and snippets.

View superMDguy's full-sized avatar

Matthew Dangerfield superMDguy

View GitHub Profile
@superMDguy
superMDguy / pug-to-html.js
Last active May 31, 2019 22:53
Automatically convert Vue single file components from Pug/Jade to HTML
const fs = require('fs')
const pug = require('pug')
const glob = require('glob')
const templateRegex = new RegExp('<template lang="pug">(.*)</template>', 's')
const attributeRegex = new RegExp(/(\S*)="/, 'g')
function compilePug(pugCode) {
let cleanedPug = pugCode.split('\n').filter(line => line.trim().length > 0)
const initialTab = cleanedPug[0].match(/^\s*/)[0]
function loadStuff() {
state.loading = true
fetch('//myapi.com/stuff')
.then(res => res.json())
.then(data => {
state.loading = false
state.stuff = data
})
}
import tuxi from 'tuxi'
import Vuex from 'vuex'
import Vue from 'vue'
import api from './api'
Vue.use(Vuex)
const store = new Vuex.Store({
strict: true, // tuxi works in strict mode!
<template>
<div class="wrapper">
<div class="empty-message" v-if="articlesTask.empty">
No articles
</div>
<div class="spinner" v-if="articlesTask.spinning">
Loading articles...
</div>
import tuxi from 'tuxi'
import api from './api'
const articlesTask = tuxi.task(api.fetchArticles)
// ⚡ Fire the api call
articlesTask.start()
// The task is immediately set to pending
console.log(articlesTask.pending) // true
/**
* Create a Vuex store module to represent states for an asynchronous API getter.
*
* Includes defaultState, actions, and mutations for a standard value gotten via asynchronous call.
* See defaultState() function for list of states included.
*
* Usage:
* Assuming we have an async call to get documents (getDocuments) which takes a payload object as an arg, here's what we can do:
*
* ----- store.js -----
@superMDguy
superMDguy / sortable-dnd.util.js
Last active December 12, 2022 20:13
SortableJS drag and drop testing utilities for cypress
// Cypress-ized and modified version of https://github.com/kemokid/scripting-sortable/blob/master/script_sortable_dnd.js
export function triggerSortableDragAndDrop(elemDrag, elemDrop) {
/*
Summary of what events this fires:
On elemDrag:
mouseDown
dragstart
On elemDrop:
dragover (repeat until it moves)
@superMDguy
superMDguy / progress.js
Last active January 31, 2018 01:24
Progress report generator bookmarklet for Khan Academy courses
const progress = Array.from(
document.querySelectorAll('p[class^="progressNumbers"]')
)
.map(x => x.innerText)
.map(txt => {
let parsed = txt.match(/(\d+) of (\d+) complete/);
return { done: parseInt(parsed[1]), total: parseInt(parsed[2]) };
});
const done = progress.map(unit => unit.done).reduce((acc, val) => acc + val);
@superMDguy
superMDguy / add_weather.py
Last active February 24, 2018 20:47
Adds weather data to dataset for kaggle "Recruit Restaurant Visitor Forecasting" competition
train.visit_date = pd.to_datetime(train.visit_date)
test.visit_date = pd.to_datetime(test.visit_date)
def add_weather(dataset):
print('Adding weather...')
air_nearest = pd.read_csv(
'../../data/raw/weather/air_store_info_with_nearest_active_station.csv')
unique_air_store_ids = list(dataset.air_store_id.unique())
weather_dir = '../../data/raw/weather/1-1-16_5-31-17_Weathe
<script>
const code = '(print (+ 1 (* 2 3) 3))'
const parsed = parse(code)
console.debug('Parsed AST', parsed)
evaluate(parsed[0])
function parse(phrase) {
let seek = 0
const parsed = []