Skip to content

Instantly share code, notes, and snippets.

View deavial's full-sized avatar
😈
Up to no good, probably.

Deavial deavial

😈
Up to no good, probably.
View GitHub Profile
@deavial
deavial / rx-websockets.jsx
Created September 9, 2022 18:15 — forked from sergiodxa/rx-websockets.jsx
Example possible usage of Rx for (fake) WebSocket Server
import { Observable } from 'rx';
import { EventEmitter } from 'events';
import { Map as map } from 'immutable';
// base para crear sockets
class Socket extends EventEmitter {
constructor(id) {
super(id);
this.id = id;
}
@deavial
deavial / async-thread.js
Created September 9, 2022 18:13 — forked from sergiodxa/async-thread.js
Use WebWorkers and promises to run sync heavy functions in a worker (process) and get the result in a promise
function asyncThread(fn, ...args) {
if (!window.Worker) throw Promise.reject(
new ReferenceError(`WebWorkers aren't available.`)
);
const fnWorker = `
self.onmessage = function(message) {
(${fn.toString()})
.apply(null, message.data)
.then(result => self.postMessage(result));
@deavial
deavial / entry.server.tsx
Created September 9, 2022 18:00 — forked from sergiodxa/entry.server.tsx
Dynamically generate a PDF with Remix
import { renderToStream } from "@react-pdf/renderer";
import ReactDOMServer from "react-dom/server";
import { EntryContext, Headers, RemixServer, Request, Response } from "remix";
import PDF, { loader } from "./pdfs/my-pdf.server";
async function handlePDFRequest(request: Request, headers: Headers) {
// get the data for the PDF
let response = await loader({ request, context: {}, params: {} });
// if it's a response return it, this means we redirected
if (response instanceof Response) return response;
@deavial
deavial / alert.js
Created October 4, 2021 20:24 — forked from farminf/alert.js
Sending PR Alerts Via Slack Using AWS Serverless and AWS CDK
const AWS = require("aws-sdk");
const fetch = require("node-fetch");
const crypto = require("crypto");
const slackChannel = process.env.SLACK_CHANNEL_URL;
const githubSecret = process.env.WEBHOOK_SECRET;
const verifyGitHubSignature = (req = {}, secret = "") => {
const sig = req.headers["X-Hub-Signature"];
const hmac = crypto.createHmac("sha1", secret);
const digest = Buffer.from(
@deavial
deavial / umd.js
Created October 4, 2021 20:23
umd template
(function (root, factory) {
var name = "FooMod";
var deps = ["this", "that", "whatnot"];
if (typeof exports === "object") {
module.exports = factory.apply(undefined, deps.map(function (d) { return require(d); }));
} else if (typeof define === "function" && define.amd) {
define(deps, factory);
} else {
el.set('contentEditable', true)
.addEvents({
keydown: function(e){ if (e.key == 'enter') e.preventDefault(); },
keypress: function(e){ if (e.event.which == 0 && e.code == 13) e.preventDefault(); },
blur: function(){ var text = this.get('text'); this.set('text', text); }
});
# List users by average and maximum session length.
SELECT person, max(client.runtime_ms), avg(client.runtime_ms)
FROM item_occurrence
GROUP BY 1
ORDER BY 2 DESC
# List active date ranges for each deploy.
SELECT client.javascript.code_version, min(timestamp), max(timestamp)
FROM item_occurrence
GROUP BY 1
@deavial
deavial / Enhance.js
Created September 13, 2017 08:35 — forked from sebmarkbage/Enhance.js
Higher-order Components
import { Component } from "React";
export var Enhance = ComposedComponent => class extends Component {
constructor() {
this.state = { data: null };
}
componentDidMount() {
this.setState({ data: 'Hello' });
}
render() {
@deavial
deavial / JavascriptModulePatterns
Created June 3, 2016 03:41 — forked from ShMcK/JavascriptModulePatterns
Javascript (ES5) Module Patterns
'use strict';
// 1. Revealing Module Pattern
var revModule = function (param) {
return {
// public
funk: funk
};
// private
@deavial
deavial / defunctr-cla
Created April 14, 2016 16:45
defunctr cla
**Individual Contributor License Agreement v3.0**
Thank you for Your interest in the Defunctr Open Source Project. This document clarifies the terms under which You, the person listed below, may make Contributions — which may include without limitation, software, bug fixes, configuration changes, documentation, art work, creative design, video, or any other materials — to any of the projects owned or managed by Cinecove Digital.
[Please complete information about You and the Contributions](#void). If You have questions about these terms, please contact us at [legal@cinecove.com](mailto:legal@cinecove.com).
You accept and agree to the following terms and conditions for Your present and future Contributions submitted to the Defunctr Open Source Project. Except for the license granted herein to the Defunctr Open Source Project, You reserve all right, title, and interest in and to Your Contributions.
**Licenses**