Skip to content

Instantly share code, notes, and snippets.

View EliaECoyote's full-sized avatar
🌚
ㅋㅋㅋㅋ

Elia Camposilvan EliaECoyote

🌚
ㅋㅋㅋㅋ
View GitHub Profile
@EliaECoyote
EliaECoyote / whilePressed.ts
Created September 6, 2017 09:13
Angular Directive that fires a callback function while the tag is pressed
import * as angular from "angular";
class WhilePressedController {
private intervalPromise: Function;
private intervalTime: number;
static $inject = ['$scope', '$element', '$interval'];
constructor(private scope, private element, private interval) {
@EliaECoyote
EliaECoyote / scriptLoader.ts
Created September 6, 2017 09:15
A Typescript script loader that adds script tags to your document object Edit Add topics
export const scriptLoader = {
load: (src) => {
return new Promise((resolve, reject) => {
if (document.querySelector("script[src=\"" + src + "\"]")) {
resolve();
return;
}
const el = document.createElement("script");
@EliaECoyote
EliaECoyote / smoothScroll.js
Last active September 7, 2017 21:35
jquery smooth scroll
export function smoothScrollingTo(target) {
$('html,body').animate({ scrollTop:$(target).offset().top }, 500);
}
/** smooth scroll on anchor */
/*
$('a[href*=\\#]').on('click', function(event){
event.preventDefault();
smoothScrollingTo(this.hash);
});
@EliaECoyote
EliaECoyote / firebase_cloud_function_conf.json
Last active February 24, 2018 15:10
firebase configuration - cloud functions for firebase hosting
{
"hosting": {
"public": "dist",
"rewrites": [
{ "source": "/events/*", "function": "eventsReqHandler" },
{ "source": "**", "destination": "/index.html" }
]
}
}
import * as functions from 'firebase-functions';
import * as express from 'express';
const app = express();
app.get('/events/:id', (request, response) => {
const userAgent = request.get('user-agent');
if (userAgent.indexOf("facebookexternalhit") === 0) {
res.status(200).send(`
<!doctype html>
import * as functions from 'firebase-functions';
import * as express from 'express';
const app = express();
function buildOgTemplate(event: any) {
return `
<!DOCTYPE html>
<html>
<head>
function removeByKey (myObj, deleteKey) {
return Object.keys(myObj)
.filter(key => key !== deleteKey)
.reduce((result, current) => {
result[current] = myObj[current];
return result;
}, {});
}
@EliaECoyote
EliaECoyote / machine.js
Last active November 6, 2019 09:50
Generated by XState Viz: https://xstate.js.org/viz
"use strict";
// machine state definitions
var States;
(function (States) {
States["idle"] = "idle";
States["userLogged"] = "userLogged";
States["userUnlogged"] = "userUnlogged";
States["startTimePending"] = "startTimePending";
States["startTimeReady"] = "startTimeReady";
})(States || (States = {}));
@EliaECoyote
EliaECoyote / machine.js
Last active November 13, 2019 11:01
Generated by XState Viz: https://xstate.js.org/viz
const States = {
play: 'play',
error: 'error',
idle: 'idle'
}
const Transitions = {
loginSuccessful: 'loginSuccessful',
didDisplaySharer: 'didDisplaySharer',
cancelPlayRequest:
@EliaECoyote
EliaECoyote / UseMachine.re
Created November 27, 2019 08:34
ReasonML useMachine react hook
/**
* describes the outcome of the machine reducer
* fn.
* The Invalid variant value describes the case
* where an undesired event is received
* (cannot receive the event while being in
* current state).
* The Ignored variant value describes the case
* where we just want to not take action after
* receiving a specific event.