Skip to content

Instantly share code, notes, and snippets.

@ThomasHambach
ThomasHambach / ngRouter.ts
Last active December 8, 2018 08:05
Angular 1, Vue 2, ui-router control.
// Vue path changer that ties in with ui-router.
// Add this somewhere, such as in your app runner, to catch the event.
addEventListener("requestPathChange", (e: CustomEventInit) => {
$state.go(e.detail.path, e.detail.params);
});
@ThomasHambach
ThomasHambach / express-joi-typescript-validate-middleware.ts
Last active September 25, 2019 19:05
Express + Joi + Typescript validation middleware
app.get("/some-endpoint", validate({...}), (req, res, next) => {});
@ThomasHambach
ThomasHambach / breadCrumbs.directive.js
Created June 3, 2016 02:27
Angular breadcrumb with ui router resolve interpolation
(function () {
'use strict';
const template = '<ol class="breadcrumb">' +
'<li ng-repeat="c in crumbs">' +
'<a ui-sref="{{c.name}}">{{c.label}}</a>' +
'</li>' +
'</ol>';
@ThomasHambach
ThomasHambach / example.html
Created May 12, 2016 09:24
Angular 1.x Show Password Form Field Directive
<input type="password" show-password="">
@ThomasHambach
ThomasHambach / ngJsdifflib.js
Created February 11, 2016 04:00
Angular JSDiffLib
'use strict';
angular.module('ngJsdifflib', []);
angular.module('ngJsdifflib').directive('jsdifflib', function () {
return {
restrict: 'E',
scope: {
previous: '=',
current: '='
@ThomasHambach
ThomasHambach / web.config
Created November 3, 2015 08:14
Angular fullstack on IIS
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<customErrors mode="off"/>
</system.web>
<system.webServer>
<httpErrors existingResponse="passthrough"/>
<handlers>
<add name="iisnode" path="server/app.js" verb="*" modules="iisnode"/>
</handlers>
@ThomasHambach
ThomasHambach / example.js
Created July 20, 2015 03:41
Node ODBC upsert module
var wodbc = require("./wodbc")();
var data = {
UserName: 'Jane Doe'
}
wodbc.upsert('User', 'UserId', data, function (err, insertId) { ...
@ThomasHambach
ThomasHambach / routes.rb
Created February 9, 2015 11:01
Rails redirect to default locale
Rails.application.routes.draw do
scope "/:locale" do
# blablabla..
end
root to: "welcome#index"
get '/:locale' => 'welcome#index', :as => 'locale_root'
end
@ThomasHambach
ThomasHambach / drupal.js
Created May 14, 2014 08:15
Drupal 7 Execute custom function when doing AJAX load
(function($) {
Drupal.behaviors.contact = {
attach: function (context, settings) {
$('.webform-client-form input').attr('readonly', false);
// Actions are stored in Drupal.ajax, every ajax call these identifiers might change.
$.each(Drupal.ajax, function(k, v) {
if(k.match(/edit-submitted-about/g)) { // The identifier I was aiming for was prefixed with "edit-submitted-about".
Drupal.ajax[k].options.beforeSerialize = function(element, options) {
@ThomasHambach
ThomasHambach / mymodule.module
Created May 8, 2014 08:42
Drupal 7, overwrite menu block tree
<?php
/**
* Implements hook_menu_block_tree_alter().
*/
function mymodule_menu_block_tree_alter(&$tree, &$config) {
global $language;
$default = language_default('language');
if($language->language != $default) {