Skip to content

Instantly share code, notes, and snippets.

@dagingaa
dagingaa / backdateStripeSubscription.js
Created February 5, 2020 08:42
Backdates a Stripe subscription without triggering proration. Probably the easiest way to undo a mistake if you ended up screwing something up royally and need to reset.
const stripe = require("stripe")("api_key");
const CUSTOMER = "";
const PLAN = "";
const quantity = 1;
const startTimeInSecondsSinceEpoch = 0;
const billingCycleAnchorInSecondsSinceEpoch = 0;
async function foo() {
const subscription = await stripe.subscriptions.create({
// run in console on a https page
stream = await navigator.mediaDevices.getUserMedia({ video: true, audio:true })
video = document.createElement("video");
video.muted = true;
video.srcObject = stream;
await video.play();
canvas = document.createElement("canvas")
ctx = canvas.getContext("2d")
ctx.drawImage(video, 0, 0, video.videoWidth, video.videoHeight);
imageData = ctx.getImageData(0,0,video.videoWidth, video.videoHeight)
src = "url_to_imgur"
img = new Image();
img.crossOrigin = "Anonymous";
img.addEventListener("load", analyze, false);
img.src = src;
function analyze() {
canvas = document.createElement("canvas")
ctx = canvas.getContext("2d")
const dgram = require('dgram');
// STUN binding request
const bind = Buffer.from('000300002112a4425f73a4b270529f877091d580', 'hex');
const socket = dgram.createSocket('udp4');
socket.on('message', (data) => {
console.log('STUN BINDING RESPONSE', data.toString());
});
if ('mediaCapabilities' in navigator && 'encodingInfo' in navigator.mediaCapabilities) {
const videoFileConfiguration = {
type : 'record',
video : {
contentType: "video/webm;codecs=vp8",
width: 1920,
height: 1080,
bitrate: 2500000,
framerate: 30,
}
@dagingaa
dagingaa / webrtcsupportgate.js
Created November 27, 2017 19:35
WebRTCSupportGate
function WebRtcSupportGate({
children,
forceUnsupported,
forceUnsupportedIos,
forceUnsupportedFacebook,
forceUnsupportedInApp,
}) {
const isWebRtcSupported =
!!global.RTCPeerConnection &&
!!global.navigator.mediaDevices &&
@dagingaa
dagingaa / passport-grean.js
Created September 5, 2017 11:59
A small wrapper around openid-client passport for integrating with Grean EasyID
"use strict";
const { Issuer, Strategy } = require("openid-client");
Issuer.defaultHttpOptions = { timeout: 5000 };
function createUser(userinfo) {
const name = userinfo.name.split(",");
return {
id: userinfo.uniqueuserid,

Keybase proof

I hereby claim:

  • I am dagingaa on github.
  • I am daginge (https://keybase.io/daginge) on keybase.
  • I have a public key ASAa1y7IlordCfcpNPe64jomY7ui1GgbuwLYBDQdq8D1mgo

To claim this, I am signing this object:

@dagingaa
dagingaa / refactor-functions-params-to-obj-destructuring.js
Created September 21, 2016 11:05
This is a non-working codemod that tried to refactor specific functions with multiple parameters into a single object with destructuring. It failed.
export default function transformer(file, api) {
const j = api.jscodeshift;
const name = "subscribeToPlan";
const newName = name;
const root = j(file.source);
root
.find(j.MethodDefinition)
.filter(path => !!path.value.key.name)
@dagingaa
dagingaa / prototype-to-class.js
Last active December 23, 2022 11:38
Codemod to transform well-written function prototype style classes into the new ES2015 syntax. Requires jscodeshift.
module.exports = (file, api, options) => {
const j = api.jscodeshift;
const root = j(file.source);
// We have to add "use strict" for node to play nice
// Taken from https://github.com/cpojer/js-codemod/blob/master/transforms/use-strict.js
const hasStrictMode = body =>
body.some(
statement => j.match(statement, {
type: 'ExpressionStatement',