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(
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 / SAP_CLA
Created March 19, 2016 01:09 — forked from CLAassistant/SAP_CLA
SAP Individual Contributor License Agreement
###SAP Individual Contributor License Agreement
Thank you for your interest in contributing to open source software projects (“Projects”) made available by SAP SE or its affiliates (“SAP”). This Individual Contributor License Agreement (“Agreement”) sets out the terms governing any source code, object code, bug fixes, configuration changes, tools, specifications, documentation, data, materials, feedback, information or other works of authorship that you submit or have submitted, in any form and in any manner, to SAP in respect of any of the Projects (collectively “Contributions”). If you have any questions respecting this Agreement, please contact opensource@sap.com.
You agree that the following terms apply to all of your past, present and future Contributions. Except for the licenses granted in this Agreement, you retain all of your right, title and interest in and to your Contributions.
**Copyright License.** You hereby grant, and agree to grant, to SAP a non-exclusive, perpetual, irrevocable, worldwid
@deavial
deavial / log
Created May 21, 2014 15:57 — forked from stefanoortisi/log
// usage: log('inside coolFunc', this, arguments);
// paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
window.log = function(){
log.history = log.history || []; // store logs to an array for reference
log.history.push(arguments);
arguments.callee = arguments.callee.caller;
if(this.console) console.log( Array.prototype.slice.call(arguments) );
};