Skip to content

Instantly share code, notes, and snippets.

@stevenkaspar
stevenkaspar / index.js
Created July 15, 2022 20:01
HTML Table to JSON
(() => {
const table = document.querySelector('#COVERAGECLASSCODES')
const rows = table.querySelectorAll('tr')
const data_rows = []
rows.forEach((row) => {
const data_row = []
const cells = row.querySelectorAll('td')
cells.forEach((cell) => data_row.push(cell.innerText.trim()))
const object = {
code: data_row[0],
@stevenkaspar
stevenkaspar / index.js
Last active October 31, 2022 14:57
Nodejs - stream with 'drain' and async/await
// prevents "backpressuring" when writing to stream
const write = (writer, data) => {
return new Promise((resolve) => {
if (!writer.write(data)) {
writer.once('drain', resolve)
}
else {
resolve()
}
})
@stevenkaspar
stevenkaspar / README.md
Last active February 25, 2019 14:07
FTP(S) using vsftpd

Scripts and config files for setting up FTP and FTPS on Ubuntu 18.04 LTS (works elsewhere but that is where I've used these steps)

  1. Run install.sh
  2. Paste vsftpd.conf into /etc/vsftpd.conf
  3. nano adduser.sh and paste in script
  4. chmod +x adduser.sh
  5. nano adduser-admin.sh and paste in script
  6. chmod +x adduser-admin.sh

Add users with

@stevenkaspar
stevenkaspar / README.md
Created February 19, 2019 13:10
Bash - Print lines from large file

Allows printing a large file by giving a line range

Helpfull when you have a large file that can't be loaded into a text editor but you want to inspect it

Usage

./print_lines.sh FILE START_LINE END_LINE
./print_lines.sh ./some-large-file.xml 1000 2000
@stevenkaspar
stevenkaspar / logout.js
Last active February 12, 2018 19:43
React HOC Logout - Apollo Example
import React from 'react';
import { withApollo } from 'react-apollo'
// will add a logout function to this.props when used around a component
// i.e.
// export default logout(LogoutButton)
const logout = function(WrappedComponent) {
class Logout extends React.Component {
constructor(props) {
@stevenkaspar
stevenkaspar / README.md
Last active December 20, 2017 15:51
Gulpfile Atomic CSS Builder

You can use the above 2 files to create dynamically generated atomic CSS files

I only added pug and React support but it would be very easy to add more

Say you have this file structure. You can use the above config to get all CSS classes defined in your app.jsx file and views files that match a key in the config.yaml file and build a CSS file that has only the used classes

.
├── gulpfile.js
├── config.yaml
Verifying that "stevenkaspar.id" is my Blockstack ID. https://onename.com/stevenkaspar
@stevenkaspar
stevenkaspar / CustomIframe.jsx
Created October 27, 2017 19:38
React Iframe for Writing to contentDocument
/**
* This has a specific use case for writing to the contentDocument allowing for a separated scope
*
* There are probably other ways to do this with ShadowDom but this works well for my purposes
*
* USAGE:
*
* <CustomIframe html={<head><title>Doc Title</title></head><body>Hello React User</body>} />
*
*/
@stevenkaspar
stevenkaspar / three columns.html
Last active October 4, 2017 14:51
Responsive Email Templates
<!--[if (gte mso 9)|(IE)]>
<table width="600" align="center" style="border-spacing: 0; font-family: sans-serif; color: #333333;"><tr>
<td style="padding: 0;">
<![endif]-->
<table align="center" style="border-spacing: 0; font-family: sans-serif; color: #333333; margin: 0 auto; width: 100%; max-width: 600px;">
<tr>
<td style="padding: 0; text-align: center; font-size: 0;">
<!--[if (gte mso 9)|(IE)]>
<table width="100%" style="border-spacing: 0; font-family: sans-serif; color: #333333;"><tr>
<td width="33%" valign="top" style="padding: 0;">
'use strict';
const gulp = require('gulp');
const shell = require('gulp-shell')
const spawn = require('child_process').spawn;
const fs = require('fs');
const mkdirp = require('mkdirp');
const pug = require('pug');
const marked = require('marked');
const path = require('path');