Skip to content

Instantly share code, notes, and snippets.

@deanohyeah
deanohyeah / bash_flags_and_input_variables.sh
Created March 27, 2020 19:13
Parse flags passed into a script and provide a way to enter info, password username
while test $# -gt 0; do
case "$1" in
-h|--help)
echo "[options] test_file test_file is name of individual test file you want to run"
echo " "
echo "options:"
echo "-h, --help show brief help"
echo "--headless=BOOLEAN for running tests in your chrome browser, only run one test at a time"
exit 0
;;
@deanohyeah
deanohyeah / index.d.ts
Created February 25, 2020 16:51
typescript declarations for parent application from npm module
// ./custom_types/performanceEntry'
declare global {
export interface PerformanceEntry {
transferSize: number,
encodedBodySize: number,
decodedBodySize: number,
responseStart: number,
responseEnd: number,
requestStart: number,
attribution: Array<any>,
@deanohyeah
deanohyeah / make_request.js
Created August 18, 2018 20:53
Js fetch boilerplate
const makeRequest = async function ({
url,
body = {},
method = 'GET',
headers = {},
}) {
const bodyString = JSON.stringify(body)
let json
const response = await fetch(url, {
@deanohyeah
deanohyeah / sequential_promise_list.js
Last active August 5, 2017 22:43
iterate through a list of promises, waiting for the item to resolve before moving to the next item
function seqPromise(){
function* generator() {
let func = () => Promise.resolve()
while(true)
func = yield func()
}
const gen = generator()
return function genPush(list, fn) {
function fnWrap(fn, item) {
return () => fn(item)
import React from 'react';
import { render } from 'react-dom';
const block = () => {
let state = {}
const clearState = () => {
state = {}
}
class RenderBlock extends React.Component {
@deanohyeah
deanohyeah / close_crucible_reviews.js
Created July 15, 2017 08:19
A js executable script to close all crucible reviews for user.
#!/usr/bin/env node
/* eslint-disable import/no-commonjs */
const request = require('request')
const Promise = require('bluebird')
const FISHEYE_BASE_URL = 'FILL_IN_URL'
const userName = (process.argv[2]).toString()
const password = (process.argv[3]).toString()
let token
@deanohyeah
deanohyeah / optional_flag_parsing.sh
Created July 12, 2017 16:35
Shell: example of optional flag parsing
# this function will search all passed arguments for optionalFlag's existence
function test() {
if [[ $* == *--optionalFlagt* ]]
then
do stuff
else
do other stuff
fi
}
@deanohyeah
deanohyeah / cucumber_find_steps.vim
Last active June 10, 2017 05:31
Cucumber js step finder
let b:cucumber_root = '~/src/current/ui/test/features/step_definitions'
if !exists("b:cucumber_steps_glob")
let b:cucumber_steps_glob = b:cucumber_root.'/**/*'
endif
function! s:getallsteps()
let step_pattern = '\/\^.*$\/'
let steps = []
for file in split(glob(b:cucumber_steps_glob),"\n")
let lines = readfile(file)
find . -type f -print0 | xargs -0 -n 1 sed -i -e 's/module.exports.*/module.exports = ->/g
@deanohyeah
deanohyeah / batch_delete.coffee
Created June 28, 2016 21:23
use promises to batch delete things. Resolve when all complete
save: ->
# avoid making a request before one comes back
return if @prop('busy')
@prop('busy', true)
# we want to delete first so that when we call save we get updated response without the deleted models
@delete().then =>
@save()
.then (models) =>
# # add the response of models to the collection
@reset(models) if models.length