Skip to content

Instantly share code, notes, and snippets.

View zachariahtimothy's full-sized avatar

Zach Curtis zachariahtimothy

View GitHub Profile
function convert(filename) {
if (!fs.existsSync(filename)) {
debug && log(`File ${filename} does not exist`)
}
const headerElements = ['Group Name', 'Project Name', 'Scanner Name', 'Status', 'Vulnerability', 'Details', 'Additional Info', 'Severity', 'CVE', 'CWE'];
const rows = [headerElements.join(',')];
const contents = JSON.parse(fs.readFileSync(filename, { encoding: 'utf-8' }));
contents.forEach((item) => {
item.vulnerabilities.forEach((vulnerability, i) => {
const { identifiers, name, severityWithCritical } = vulnerability;
// In ActivityTypeForm.tsx
if (activityType === ActivityType.Mkt) {
return queryAndRenderActivityForm<GetActivityMarketQuery>({
activityQuery: GetActivityMarketDocument,
mutationDocument: SaveActivityMarketDocument,
queryVariables: activityId ? { id: activityId } : undefined,
onSaved,
onError,
Component: ActivityFormMarket,
mapInitialValues: (data) => {
@zachariahtimothy
zachariahtimothy / ComponentWithFetch.tsx
Last active December 7, 2018 14:59
Rest API React hook
import { useRestAPI } from './hooks/useRestAPI';
export function ComponentWithFetch() {
const result = useRestAPI<DataShape>({ url });
const { loading, error, data } = result;
if (loading) {
return <Loading />;
}
if (error) {
return <Error />;
@zachariahtimothy
zachariahtimothy / TaylorMade.js
Created November 30, 2018 15:51
Access unstated state
class TaylorMade extends React.Component {
myCounter = null;
shouldComponentUpdate() {
if (this.myCounter) {
console.log('Bomb.com, I have a counter!');
}
return true;
}
render() {
@zachariahtimothy
zachariahtimothy / generateNowConfig.js
Last active August 24, 2018 17:38
Generates a now.json file for static docker deployments on now that require .env files (which are ignored in .gitignore)
const path = require('path');
const fs = require('fs');
// Generates now.json
// Writes a now config for static site copying .env to now.json
function main() {
const baseDir = path.join(__dirname, '../');
const envFile = fs.readFileSync(path.join(baseDir, '.env'));
const envLines = envFile.toString().split('\n');
const nowConfig = {
@zachariahtimothy
zachariahtimothy / gist:aa9acd432bd382880381052016412cc6
Last active November 17, 2016 16:43
Calculate an average date in C++ based on array of dates
int wean_dates_size = bgi->wean_dates.size();
if (wean_dates_size > 0) {
pigknows::Date wean_date;
pigknows::DoubleCell dateTotals;
// Get a baseline time (date does not matter as since it will be used )
struct std::tm baseTime = {0,0,0,27,9,82}; /* October 27, 1982 (Zachs bday :) */
std::time_t x = std::mktime(&baseTime);
for(int i=0; i< wean_dates_size; ++i) {
@zachariahtimothy
zachariahtimothy / Freshbooks Estimate Hour Extraction
Created December 8, 2015 22:54
Console script to run to extract total hours from Estimate. This is helpful if you have multiple line items with multiple bill rates.
var total = 0;
$('.invbody-items').find('.quantity').each(function (i, item) {
var me = $(item).text().trim();
me = parseFloat(me, 10);
if (me) { total += me; }
});
console.log('Total Hours:', total);
@zachariahtimothy
zachariahtimothy / FlowRouterSSR and CollectionsFS
Created November 2, 2015 20:34
Sets up context for using CollectionsFS with FlowRouterSSR. Allows the .url() function to work server side.
//Hack to make CollectionFS work with FlowRouter.
if (Meteor.isServer) {
let originalFind = Collections.Media.find;
let originalFindOne = Collections.Media.findOne;
Collections.Media.__proto__.findOne = function (selector, options) {
let self = this;
return FlowRouter.ssrContext.withValue(null, function() {
return originalFindOne.call(self, selector, options);
});
@zachariahtimothy
zachariahtimothy / RequirejsStub.js
Created April 24, 2013 20:35
RequireJS ADM Stub
define([], function(){
'use strict';
var MODULE = {
};
return MODULE;
});
@zachariahtimothy
zachariahtimothy / gist:5455126
Created April 24, 2013 20:05
Code to export email addresses and forwarders from cPanel using Browser developer tools
// Email Addresses ///
var rows = $("#table_email_accts tr.dt_info_row"),
returnString = "";
rows.each(function(i, item){
var tdList = [];
$(item).find('td:eq(0)').each(function(s, subItem){
tdList.push($(subItem).text());
});
returnString += tdList + "\n";
});