Skip to content

Instantly share code, notes, and snippets.

View joeyguerra's full-sized avatar
😀
chatting

Joey Guerra joeyguerra

😀
chatting
View GitHub Profile
@joeyguerra
joeyguerra / notificationcenter.js
Created November 25, 2013 01:17
Client side notification center. Publsih/Subscribe implementation in Javascript.
(function(module){
var observers = [];
module.exports.notificationcenter = {
publish: function(notification, publisher, info){
var ubounds = observers.length;
var i = 0;
for(i; i<ubounds; i++){
if(!observers[i]) continue;
if(observers[i].notification != notification) continue;
if(observers[i].publisher != null && observers[i].publisher != publisher) continue;

Keybase proof

I hereby claim:

  • I am joeyguerra on github.
  • I am joeyguerra (https://keybase.io/joeyguerra) on keybase.
  • I have a public key ASBDxkxeKV2rhI1xg9U9HoLNphwjWh_qk2Sj5V969ys6fAo

To claim this, I am signing this object:

const pipe = (...fns) => x => fns.reduce((y, f) => f(y), x)
@joeyguerra
joeyguerra / ParseEnvFile.mjs
Created September 5, 2020 02:46
Parse a .env file key/value pairs
import assert from "assert"
describe("PropertyFile - externalize configuraiton with environment variables", ()=>{
it("Should parse an env file", async done => {
const env = `
CLIENT_ID="something"
CLIENT_SECRET="something"
# something id
ID=1
`
let config = {}
import assert from "assert"
import http2 from "http2"
//using mocha
describe("Http2", ()=>{
it("Should make a get request to google with http2", done => {
const uri = "https://www.google.com"
const client = http2.connect(uri);
const req = client.request({
[http2.constants.HTTP2_HEADER_SCHEME]: "https",
[http2.constants.HTTP2_HEADER_METHOD]: http2.constants.HTTP2_METHOD_GET,
@joeyguerra
joeyguerra / getbitcoin.js
Created January 9, 2021 04:24
BitCoin price
Notification.requestPermission();
setInterval(async ()=>{
let data = await (await fetch("https://api.coindesk.com/v1/bpi/currentprice.json")).json();
document.body.innerHTML = `${data.time.updated}:%20${data.bpi.USD.rate}`;
if(Notification.permission == "granted") new Notification(`BitCoin Price: $${data.bpi.USD.rate}`);
},10000);
@joeyguerra
joeyguerra / dredis-cli.sh
Last active November 6, 2021 16:09
Connect to locally running Redis Server with Docker Container
docker run --rm -it --name redis-cli redis redis-cli -h $IPADDRESS -a $REDIS_PASSWORD
@joeyguerra
joeyguerra / init-existing-repo.sh
Created November 7, 2021 21:25
New Github project with existing code on local machine
#!/bin/zsh
# example run: ./init.sh git@github.com:joeyguerra/100-days-of-code.git
git init
git remote add origin $1
git add .
git commit -m "initial commit"
git push -u origin main
f(events) -> state
match f(state, event) -> state
f(state, command) -> events
@joeyguerra
joeyguerra / Debounce.mjs
Created February 6, 2022 17:52
Debounce in javascript.
import assert from 'assert';
describe('Debounce', ()=>{
it('When called super fast, then should only increment once', done=>{
const debounce = timer => (fn, timeout) => {
clearTimeout(timer);
timer = setTimeout(fn, timeout);
return timer;
};
let timer = null
let actual = 0;