Skip to content

Instantly share code, notes, and snippets.

@guillaume86
guillaume86 / MiniProfiler.js
Last active March 12, 2024 15:08
Integrating MiniProfiler into a SPA (React, Angular, Vue, etc)
/**
* GET /mini-profiler-includes returns a <script> element
* Re-create it in the DOM and append it to the document.
*
* Using ES5 for maximum compatibilty.
*/
(function (window) {
if ("MiniProfiler" in window) return console.warn("MiniProfiler already imported.");
var ERROR_MESSAGE = "MiniProfiler could not be loaded: ";
namespace Redux {
export interface Action<TType extends string, TPayload> {
type: TType;
payload: TPayload;
}
export interface Thunk<TAction, TResult> {
(dispatch: Dispatch<TAction>, getState: () => any): TResult;
}
@guillaume86
guillaume86 / alternative.js
Created October 18, 2016 15:36
Alternative method
/*
* <style> injection browser plugin
*/
// NB hot reloading support here
function cssInject(style, css) {
if (style) {
style.innerHTML = css;
} else {
style = document.createElement('style');
{
"results":{
"opensearch:Query":{
"#text":"",
"role":"request",
"startPage":"1"
},
"opensearch:totalResults":"0",
"opensearch:startIndex":"0",
"opensearch:itemsPerPage":"30",
@guillaume86
guillaume86 / basic-main.js
Created July 6, 2015 16:03
redux-react-router
import React from 'react';
import { createRedux } from 'redux';
import { provide } from 'redux/react';
import { Router } from 'react-router';
import { history } from 'react-router/lib/HashHistory';
import routes from './routes';
const redux = createRedux({});
@provide(redux)
@guillaume86
guillaume86 / jsoncorsdb.py
Created May 10, 2014 13:15
Edited https://github.com/davidedc/jsonp-db-redux to support CORS (allowing bigger payloads)
import inspect, operator
import urllib
import re
import logging
import webapp2
import json
from google.appengine.ext import db
from google.appengine.api import users
from google.appengine.ext.webapp.util import run_wsgi_app
var $compileCache = function ($http, $templateCache, $compile) {
var cache = {};
return function (src, scope, cloneAttachFn) {
var compileFn = cache[src];
if (compileFn) {
compileFn(scope, cloneAttachFn);
} else {
$http.get(src, { cache: $templateCache }).success(function (response) {
var responseContents = angular.element('<div></div>').html(response).contents();
@guillaume86
guillaume86 / SolLewitt.Grammar
Last active December 22, 2015 05:28
SolLewitt.Grammar for Irony Parser
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Irony.Parsing;
namespace SolLewitt.Parser
{
[Language("SolLewittDrawing", "0.1", "Sol Lewitt style drawing description language")]
angular.module('ui.bootstrap.typeahead.alt', ['ui.bootstrap.position'])
/**
* A helper service that can parse typeahead's syntax (string provided by users)
* Extracted to a separate service for ease of unit testing
*/
.factory('typeaheadParser', ['$parse', function ($parse) {
var TYPEAHEAD_REGEXP = /^\s*(.*?)(?:\s+as\s+(.*?))?(?:\s+grouped\s+as\s+\((.*?\s+in\s+.*?)\))?\s+for\s+(?:([\$\w][\$\w\d]*))\s+in\s+(.*)$/;
var TYPEAHEAD_GROUP_REGEGXP = /^\s*(?:([\$\w][\$\w\d]*))\s+in\s+(.*)$/;