Skip to content

Instantly share code, notes, and snippets.

View greyscaled's full-sized avatar
🥑
avocado

Grey greyscaled

🥑
avocado
  • Hamilton, ON
  • 20:16 (UTC -04:00)
View GitHub Profile
@greyscaled
greyscaled / README.md
Last active September 19, 2022 08:59
Sequelize + Express + Migrations + Seed Starter
<table id="cardTable" class="tablesorter">
<thead>
<!-- Don't need this -->
</thead>
<tr id="card_1234" class="card-row" data-id="1234" data-name="card-name" data-elems="water fire">
<td>
<span>
<!-- don't need -->
</span>
</td>
const fs = require('fs')
const cheerio = require('cheerio')
console.log('Reading File fooTable.html...')
const parsedHTML = fs.readFileSync('./footable.html', 'utf8')
const $ = cheerio.load(parsedHTML, {
normalizeWhitespace: true
})
const db = require('../models')
db.sequelize.sync().then(function () {
// Require our JSON
const cardJson = require('../.data/cards.json').cards
// For Each card, let's associate it!
cardJson.forEach(async card => {
// get the Model for the current card
const cardModel = await db.Card.findOne({
let transaction
try {
// Unmanaged Transaction
transaction = await sequelize.transaction()
// make sure to use the transaction in options
await Team.create({...},{transaction})
// always call commit at the end
await transaction.commit()
let transaction
let teamToUpdate
try {
transaction = await sequelize.transaction() // Managed Transaction
// update the team
teamToUpdate = await Team.findOne({ where: {...}, transaction })
/* POTENTIAL ERROR - .update of null */
await teamToUpdate.update({...}, {transaction})
catch (err) {
// never forget to rollback
await transaction.rollback()
if (err instanceof TypeError) {
// we know now that we couldn't find a team
return res.status(404).send('useful message regarding team not found')
}
else if (err.message === 'tag not found') {
@greyscaled
greyscaled / paper-svg.html
Last active July 22, 2018 17:56
SVG Paper
<div class="svg-wrapper">
<svg
class="svg-paper"
id="paper"
preserveAspectRatio="xMidYMid meet"
viewbox="0 0 400 400"
width="100%"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<g class="svg-paper__group">
function draw () {
let WIDTH = visualizer.width
let HEIGHT = visualizer.height
// loop this
window.requestAnimationFrame(draw)
// get the current Data (gets placed into array arg)
player.getAnalyzerTimeBytes(1, f1visualData)
player.getAnalyzerTimeBytes(2, f2visualData)
<div class="navigation">
<input class="navigation__cbox" id="DrawerToggle" type="checkbox"/>
<label class="navigation__hamburger-box" for="DrawerToggle">
</label>
</div>