Skip to content

Instantly share code, notes, and snippets.

View apb2006's full-sized avatar

Andy Bunce apb2006

  • Quodatum
  • London, UK
View GitHub Profile
@danawoodman
danawoodman / 0-react-hello-world.md
Last active March 9, 2024 00:32
React Hello World Examples

React "Hello World" Examples

Below are a small collection of React examples to get anyone started using React. They progress from simpler to more complex/full featured.

They will hopefully get you over the initial learning curve of the hard parts of React (JSX, props vs. state, lifecycle events, etc).

Usage

You will want to create an index.html file and copy/paste the contents of 1-base.html and then create a scripts.js file and copy/paste the contents of one of the examples into it.

@Fil
Fil / zoompan.js
Created September 21, 2014 20:37
d3 zoom and pan from the keyboard
d3.select('body').on('keydown', function () {
var step = 200;
var key = d3.event.key || d3.event.keyCode; // safari doesn't know .key
switch (key) {
case 'Esc':
case 27:
zoom.translate([0, 0]).scale(1).event(mapsvg.transition());
break;
case '+':
case '=':
@joewiz
joewiz / highlight-matches.xq
Last active March 22, 2017 14:48
Highlight regex pattern matches in XML while preserving node structure, with XQuery
xquery version "3.0";
declare namespace fn="http://www.w3.org/2005/xpath-functions";
(: Search within $nodes for matches to a regular expression $pattern and apply a $highlight function :)
declare function local:highlight-matches($nodes as node()*, $pattern as xs:string, $highlight as function(xs:string) as item()* ) {
for $node in $nodes
return
typeswitch ( $node )
case element() return
@xcambar
xcambar / LICENSE
Last active November 20, 2015 12:57
Authenticated routing using AngularJS
Copyright (c) 2015 - Xavier Cambar <@ xcambar_gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
@joshkurz
joshkurz / app.js
Created August 9, 2012 03:21
AngularJs-twitterBootstrap-wysiHtml5
var demoApp = angular.module('demoApp', ['ngResource'], function($locationProvider) {
$locationProvider.hashPrefix('');
});
function MainCtrl($scope, Serv) {
$scope.selectedItem = {
value: 0,
label: ''
};
$scope.Wrapper = Serv;
@tj
tj / routes.js
Created October 15, 2011 00:23
Express routes
var app = require('../app');
console.log();
app.routes.all().forEach(function(route){
console.log(' \033[90m%s \033[36m%s\033[0m', route.method.toUpperCase(), route.path);
});
console.log();
process.exit();
@sente
sente / formatXML.js
Last active April 4, 2024 12:20
javascript to format/pretty-print XML
The MIT License (MIT)
Copyright (c) 2016 Stuart Powers
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions: