Skip to content

Instantly share code, notes, and snippets.

View krawaller's full-sized avatar

David Waller krawaller

View GitHub Profile
Drupal.verticalTabs = Drupal.verticalTabs || {};
Drupal.settings.verticalTabs = Drupal.settings.verticalTabs || {};
Drupal.behaviors.verticalTabs = function() {
if (!$('.vertical-tabs-list').size() && Drupal.settings.verticalTabs) {
var TABSETTING = "tabpos"+document.location.pathname.replace(/\//g,666);
var ul = $('<ul class="vertical-tabs-list"></ul>');
var panes = $('<div class="vertical-tabs-panes"></div>');
$.each(Drupal.settings.verticalTabs, function(k, v) {
var summary = '', cssClass = 'vertical-tabs-list-' + k;
var docCookies = {
getItem: function (sKey) {
if (!sKey || !this.hasItem(sKey)) { return null; }
return unescape(document.cookie.replace(new RegExp("(?:^|.*;\\s*)" + escape(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=\\s*((?:[^;](?!;))*[^;]?).*"), "$1"));
},
setItem: function (sKey, sValue, vEnd, sPath, sDomain, bSecure) {
if (!sKey || /^(?:expires|max\-age|path|domain|secure)$/i.test(sKey)) { return; }
var sExpires = "";
if (vEnd) {
switch (vEnd.constructor) {
@krawaller
krawaller / findglobals
Last active December 19, 2015 23:59
Version of Remy Sharps bookmarklet to check for globals, with the addition of ignoring global variables that are undefined and also alerting out a summary. If you want to add it to Chrome, there's a good guide here: http://crossbrowsertesting.com/faq/how-do-i-install-bookmarklet-google-chrome-mac-os
javascript:(function(){var e={},t,n={},r=(prompt("Ignore filter (comma sep)?","")||"").split(","),i=r.length,s=document.createElement("iframe"),o="";while(i--){n[r[i]]=1}for(i in window){if(window[i]!==undefined){e[i]={type:typeof window[i],val:window[i]}}}s.style.display="none";document.body.appendChild(s);s.src="about:blank";s=s.contentWindow||s.contentDocument;for(i in e){if(typeof s[i]!="undefined")delete e[i];else if(n[e[i].type])delete e[i]}t="addEventListener,document,location,navigator,window".split(",");i=t.length;while(--i){delete e[t[i]]}var u=[];for(i in e){u.push(i)}alert(u.length?"Found these globals: "+u.join(", ")+". See details in the console!":"No globals found!");console.dir(e)})()
@krawaller
krawaller / glyphtxt.js
Last active December 28, 2015 14:29
Convenience function for using Glyphicons in flowing text, allowing size and colour to follow from the surroundings.
txticon = function(iconname) {
var map = {
"glass": "E001",
"leaf": "E002",
"dog": "1F415",
"user": "E004",
"girl": "1F467",
"car": "E006",
"user_add": "E007",
"user_remove": "E008",
@krawaller
krawaller / directives.md
Last active January 27, 2016 08:03
Grokking angular by claims
  • ng-submit * only makes sense on a <form> tag * is just an event handler much like ng-click
  • ng-options * only makes sense on a <select> tag * enables us to have objects as selected values instead of just strings * saves us from having to type out <options ng-repeat="..." ... /> * provides additional shortcut for <optgroup> through :groupBy
  • ng-click
  • should always be a method call, don't do assignments as that relies on brittle scoping and is hard to test
@krawaller
krawaller / myapp.js
Created February 16, 2016 16:01
Weird
angular.module('myApp',[])
.factory('tags',function(){
var tags = ['urgent','blocked','boring','hard'],
callbacks = [];
return {
addTag: function(t){
tags.push(t);
callbacks.forEach(function(cb){
cb(tags)
@krawaller
krawaller / exercise1.html
Last active May 10, 2016 11:25
angular cheating
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Exercise 1</title>
<script src="../jquery.js"></script>
<script src="../angular.js"></script>
<style>
.selected {
text-decoration: line-through;
@krawaller
krawaller / ng.html
Created May 10, 2016 14:33
fun fun angular stuff :)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Exercise 1</title>
<style>
.done {
text-decoration: line-through;
}
@krawaller
krawaller / firebase.md
Created May 9, 2017 05:08
Enforcing Firebase relation validity

Say we have a database of users and roles, where each user belongs to a role. Using the denormalized Firebase approach I might store that like this:

{
  "users": {
    "abc123": {
      "name": "Joe",
      "role": "kkk333"
    },
    // lots more users
@krawaller
krawaller / typedcontainers.md
Last active May 13, 2017 05:52
typed connect

To create a container, I only need to add my AppState typings to the mapStateToProps parameter:

const mapStateToProps = (state: State) => ({
  messages: state.messaging.messages
});

const mapDispatchToProps = (dispatch) => ({
  dismissUIMessage: (num) => dispatch(actions.dismissUIMessage(num))
});