Skip to content

Instantly share code, notes, and snippets.

View tbranyen's full-sized avatar

Tim Branyen tbranyen

View GitHub Profile
@tbranyen
tbranyen / _usage.md
Last active April 19, 2024 12:24
OpenWeatherMap / Weather Icons integration
  1. Include Weather Icons in your app: https://github.com/erikflowers/weather-icons

  2. Include the below JSON in your application, for example purposes, lets assume it's a global named weatherIcons.

  3. Make a request to OpenWeatherMap:

req = $.getJSON('http://api.openweathermap.org/data/2.5/weather?q=London,uk&callback=?');
@tbranyen
tbranyen / backbone_pushstate_router.js
Last active February 25, 2024 21:38
hijack links for pushState in Backbone
// All navigation that is relative should be passed through the navigate
// method, to be processed by the router. If the link has a `data-bypass`
// attribute, bypass the delegation completely.
$(document).on("click", "a[href]:not([data-bypass])", function(evt) {
// Get the absolute anchor href.
var href = { prop: $(this).prop("href"), attr: $(this).attr("href") };
// Get the absolute root.
var root = location.protocol + "//" + location.host + Application.root;
// Ensure the root is part of the anchor href, meaning it's relative.
@tbranyen
tbranyen / defines.js
Last active February 11, 2024 20:41
AMD Flavors.
// Anonymous empty module.
define();
// Anonymous values.
define({});
define(true);
define(1234);
define(null);
define(undefined);
@tbranyen
tbranyen / events.js
Last active July 30, 2023 09:33
Rethinking events using ES6 (https://tbranyen.com/events)
const bus = {};
const get = e => (bus[e] = bus[e] || new Set());
export const listeners = new Proxy(bus, { get });
export const emit = (e, ...args) => listeners[e].forEach(fn => fn(...args));
#!/bin/bash
#
# Copyright 2011, Tim Branyen @tbranyen <tim@tabdeveloper.com>
# Dual licensed under the MIT and GPL licenses.
#
# Automatically clone single or multiple repos into a folder,
# great for setting up a git projects folder.
#
# Install: curl https://gist.github.com/raw/902154/github.sh > /usr/local/bin/gh
# chmod +x /usr/local/bin/gh
var express = require("express");
// Create the API application.
var api = express();
api.get("/v1/money", function(req, res) {
res.json({ "bling": "$$$" });
});
module.exports = api;
@tbranyen
tbranyen / test.html
Created April 28, 2022 17:11
Test page for using workers with diffHTML
<!doctype html>
<html lang="en">
<head>
<title>Worker example</title>
</head>
<body>
<main id="mount"></main>
<script src="http://localhost:8080/packages/diffhtml/dist/diffhtml.min.js"></script>
<script src="./packages/diffhtml-middleware-worker/dist/worker.js"></script>
@tbranyen
tbranyen / _setup.sh
Created May 29, 2017 04:03
Web Components <3 JSDOM
npm i jsdom-wc@11.0.0-alpha-1
@tbranyen
tbranyen / visible-proxy.js
Created December 31, 2021 18:13
Visible proxy
function makeVisibleProxy() {
const obj = {};
// Own keys must be known ahead of time for this to work
const keys = ['key1', 'key2'];
// Map each known key to the obj, but make the getter "lazy"
keys.forEach(keyName => {
const desc = {
configurable: true,
@tbranyen
tbranyen / git_profanity_check.js
Last active October 8, 2021 23:02
git profanity check
#!/usr/bin/env node
// Copyright 2011, Tim Branyen @tbranyen <tim@tabdeveloper.com>
// Last Updated: Oct 2021 - Supports NodeGit 0.27.0
// Dual licensed under the MIT and GPL licenses.
// Script to detect cursewords in commit messages and provide the
// offending commit sha's.
// vim: ft=javascript
const { Repository } = require('nodegit');