Skip to content

Instantly share code, notes, and snippets.

@justinobney
justinobney / XmlToSql.sql
Created April 16, 2013 16:44
Import date from XML into SQL
-- Thanks to: http://pratchev.blogspot.com/2008/11/import-xml-file-to-sql-table.html
INSERT INTO Equipment (Id, Location, Unit, FullDescription, Equipment, PressureRating, Quantity, ReactorMaterialOfConstruction, ReactorCapacityGallons)
SELECT X.equipment.value('@id', 'INT'),
X.equipment.query('Location').value('.', 'VARCHAR(500)'),
X.equipment.query('Unit').value('.', 'VARCHAR(50)'),
X.equipment.query('Full_description').value('.', 'VARCHAR(500)'),
X.equipment.query('Equipment').value('.', 'VARCHAR(50)'),
X.equipment.query('Pressure_Rating').value('.', 'VARCHAR(50)'),
X.equipment.query('Quantity').value('.', 'VARCHAR(50)'),
@justinobney
justinobney / angular-get-service-console.js
Last active April 15, 2021 16:29
Get a reference to some angular service in the console
// Get the injector
var injector = angular.element($0/*'[data-ng-app], [ng-app]'*/).injector();
// Get the service
var Service = injector.get('Service');
// Use it!
// Service.addNotification('Some Notification', 'info');
<script type="text/ng-template" id="one.html">
<div>This is first template</div>
</script>
<script type="text/ng-template" id="two.html">
<div>This is second template</div>
</script>
@justinobney
justinobney / ng-preload-templates.js
Created July 1, 2013 14:37
Preload all templates
angular.module('app', [])
.run(['$route', '$http', '$templateCache', function($route, $http, $templateCache) {
// Cache all templates on App Start
angular.forEach($route.routes, function(r) {
if (r.templateUrl) {
$http.get(r.templateUrl, {cache: $templateCache});
}
});
});
@justinobney
justinobney / factorial_cache.js
Last active December 20, 2015 00:09
Simple JS Factorial Calculator
(function () {
'use strict';
var cache = {};
function factorial(number) {
var keyResult;
var cacheKey = number.toString();
console.log('Calculating factorial for ' + number);
if (cache[cacheKey]) {
@justinobney
justinobney / ng-getWatcherCount.js
Created September 5, 2013 11:29
Gets the number of watchers on an AngularJS App
(function () {
var root = $($0);
var watchers = [];
var f = function (element) {
if (element.data().hasOwnProperty('$scope')) {
angular.forEach(element.data().$scope.$$watchers, function (watcher) {
watchers.push(watcher);
});
}
@justinobney
justinobney / uuid.js
Created September 19, 2013 13:55
UUID in JS
var svc = {
new: function() {
function _p8(s) {
var p = (Math.random().toString(16)+"000000000").substr(2,8);
return s ? "-" + p.substr(0,4) + "-" + p.substr(4,4) : p ;
}
return _p8() + _p8(true) + _p8(true) + _p8();
},
empty: function() {
@justinobney
justinobney / redrawStyle.js
Last active December 27, 2015 10:39
Redraw the UI styles
function repaint(){
document.body.removeChild(document.body.appendChild(document.createElement('style')));
}
/**
* Example of using an angular provider to build an api service.
* @author Jeremy Elbourn (jelbourn@google.com)
*/
/** Namespace for the application. */
var app = {};
/******************************************************************************/
@justinobney
justinobney / withOverflowingChildren.jQuery.js
Created June 4, 2014 20:31
jQuery plugin to find overflowing direct children of an element.
jQuery.fn.withOverflowingChildren = function (cb) {
var parent = jQuery(this);
var p = parent.get(0);
var children = parent.find('> *');
var len = children.length
var parentCoords = p.getBoundingClientRect();
var called = false
while(len){
if(!isInParent(children.get(len -1))){