Skip to content

Instantly share code, notes, and snippets.

View JeffML's full-sized avatar
🏠
Barely working

Jeff Lowery JeffML

🏠
Barely working
View GitHub Profile
@JeffML
JeffML / MillerRabinTest.js
Created November 16, 2021 00:35
Miller-Rabin test using BigInt
View MillerRabinTest.js
// Javascript program Miller-Rabin primality test
// based on JavaScript code found at https://www.geeksforgeeks.org/primality-test-set-3-miller-rabin/
// Utility function to do
// modular exponentiation.
// It returns (x^y) % p
function power(x, y, p)
{
View pokerjson.js
[
{
"label": "A",
"cells": {
"values": [
84.97,
63.49,
62.57,
61.63,
60.7,
@JeffML
JeffML / heatmapdata.json
Last active August 21, 2019 23:09
example of data returned by jsheatmap
View heatmapdata.json
{
"headings": [
"Jun",
"Jul",
"Aug",
"Sep"
],
"high": 9,
"low": 4,
"rows": [
View Editor.js
export default function Editor(props) {
const { setEditing } = props;
return (
<Query query={LAUNCHES}>
{({ data, loading, error }) => {
if (loading) return <p>Loading...</p>;
if (error) return <p>ERROR</p>;
return (
<Fragment>
<Submit />
View Submit.js
// Editor.js
const LOGIN = gql`
mutation login {
login(email:"${faker.internet.email}")
}
`
const Submit = (props) => {
return <Mutation mutation={LOGIN} update={(cache, { data }) => sessionStorage.setItem('auth', data.login)}>
View Launches.js
import React, { Fragment } from 'react';
import { Query } from 'react-apollo';
import gql from 'graphql-tag';
const qLaunches = gql`query ls {
launches {
launches {
id
site
mission {
View index.js
const { Worker, isMainThread } = require("worker_threads");
function runService(workerData) {
const worker = new Worker("./service.js", { workerData });
worker.postMessage("once");
worker.on("message", incoming => console.log({ incoming }));
worker.on("error", code => new Error(`Worker error with exit code ${code}`));
worker.on("exit", code =>
console.log(`Worker stopped with exit code ${code}`)
);
View service.js
const { workerData, parentPort, isMainThread } = require("worker_threads");
// You can do any heavy stuff here, in a synchronous way
// without blocking the "main thread"
parentPort.on("message", message => {
if (message === "exit") {
parentPort.postMessage("sold!");
parentPort.close();
} else {
parentPort.postMessage({ going: message });
View test.js
/* eslint-env mocha */
import chai from 'chai';
import fetch, { subscribe } from './fetch';
chai.should();
describe('subscribe, then go', function () {
this.timeout(5000);
const handlers = {
@JeffML
JeffML / fetch.js
Last active December 29, 2018 23:55
View fetch.js
/* eslint-env mocha */
/* eslint-disable import/no-extraneous-dependencies */
// see https://www.apollographql.com/docs/link/index.html#standalone
import fetch from 'node-fetch';
import { execute, makePromise } from 'apollo-link';
import { WebSocketLink } from 'apollo-link-ws';
import { SubscriptionClient } from 'subscriptions-transport-ws';
import ws from 'ws';
import { HttpLink } from 'apollo-link-http';