Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / timesheet.js
Created September 8, 2017 14:36
react-big-calendar example
import React from 'react';
import services from '../services/index';
import BigCalendar from 'react-big-calendar';
import moment from 'moment';
import 'react-big-calendar/lib/css/react-big-calendar.css';
// setting to use Saturday as the first day of the week
moment.updateLocale('en-gb', {
week : {
@stevenkaspar
stevenkaspar / flow.js
Last active June 2, 2019 03:07
VexFlow SVG Javascript Animation
var Note = function(options){
console.log(window);
this.StaveNote = new Vex.Flow.StaveNote(options);
this.removed = false;
/**
* moves the note right from its ORIGINAL position by x pixels
* (sets the trasform: translate(x) value to x)
*/
this.setOffsetX = (x) => {
if(this.removed){
@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
@stevenkaspar
stevenkaspar / gulpfile.js
Last active November 15, 2017 17:48
KeystoneJS SASS Development Gulpfile
/**
* gulp file that will restart keystonejs app and compile sass
*/
'use strict';
var gulp = require('gulp');
var watch = require('gulp-watch');
var shell = require('gulp-shell')
var sass = require('gulp-sass');