Skip to content

Instantly share code, notes, and snippets.

View kamranayub's full-sized avatar

Kamran Ayub kamranayub

View GitHub Profile
@kamranayub
kamranayub / next.config.js
Last active September 20, 2023 20:45
React Production Profiling Support for Next.js
//
// See: https://kentcdodds.com/blog/profile-a-react-app-for-performance#build-and-measure-the-production-app
// See: https://nextjs.org/docs/api-reference/next.config.js/custom-webpack-config
const TerserPlugin = require('next/dist/compiled/terser-webpack-plugin');
module.exports = {
webpack: (config, options) => {
//
// Use profiler-enabled React builds
@kamranayub
kamranayub / ko.bindingReport.js
Last active June 14, 2023 22:34
Knockout.js Binding Performance Reporter
/**
* Performance reporting for Knockout binding handlers
*
* Usage: Include after all bindings are declared, view console for results.
*/
(function () {
var report = [];
var lastReport = 0;
var debounceWait = 500;
@kamranayub
kamranayub / machine.js
Created April 28, 2021 13:36
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@kamranayub
kamranayub / gist:935461
Created April 21, 2011 21:00
This ProxyConverter can be used with AutoMapper to help when converting Entity Framework proxied objects (i.e. DynamicProxy_xxxxxxx). Room for improvement. See: http://stackoverflow.com/questions/3441916/automapper-mapping-issue-with-inheritance-and-abstr
// See: http://stackoverflow.com/questions/3441916/automapper-mapping-issue-with-inheritance-and-abstract-base-class-on-collection/5749579#5749579
//
// For use with AutoMapper
public class ProxyConverter<TSource, TDestination> : ITypeConverter<TSource, TDestination>
where TSource : class
where TDestination : class
{
public TDestination Convert(ResolutionContext context)
{
// Get dynamic proxy base type
@kamranayub
kamranayub / README.md
Last active March 11, 2021 19:05
Enable Grammarly on Ghost Blog Admin Editor
@kamranayub
kamranayub / DataContext.js
Created April 24, 2013 05:12
A working ASP.NET Web API MVC 4 Anti-Forgery approach that also works on cloud hosts like AppHarbor. See: http://kamranicus.com/Blog/Posts/70/protip-using-anti-forgery-token-with-aspnet-web-ap
var options = {};
// jQuery options
// options.url = foo;
// CSRF Token
var csrfToken = $("input[name='__RequestVerificationToken']").val();
if (csrfToken) {
options.headers = {
@kamranayub
kamranayub / 1_TestingContext.cs
Last active October 23, 2020 15:37
Example using Ninject and Moq to create a TestingImpersonationContext. All it does is replace the bound dependency with a new impersonated mock and then replaces it once disposed. Relies on a testing context that is available to any test class (could also be a test base class). `UserRepository` is just an example of code that retrieves a user fr…
public class TestingContext {
private IKernel _kernel;
public TestingContext() {
// create initial Strict mock that can always be setup outside impersonation context
UserContext = new Mock<IUserContext>(MockBehavior.Strict);
// register dependencies
_kernel = CreateKernel();
@kamranayub
kamranayub / msbuild.js
Last active May 20, 2020 15:14
Make MSBuild 2020 player stretch across the window and chat below. Hit F12 and paste into console.
// F12 Dev Tools and copy and paste into console!
// Stretches studio player 100% and chat below.
var studioPlayer = document.querySelector("studio-player");
var studioVideo = document.querySelector(
".home-page__live-stream--content__video"
);
var chat = document.querySelector(".home-page__live-stream__info");
if (studioPlayer && studioVideo && chat) {
studioPlayer.style.display = "block";
@kamranayub
kamranayub / ko.extendes.urlSync.js
Created May 11, 2015 16:19
Knockout Extender: URLSync - syncs observable value with URL hash
/**
* An extender that syncs the observable with the address
* bar (using hash fragment). Will load from URL hash or
* querystring (at time of creation) and will
* update hash when observable changes.
*
* Options: string|object
* String: Query parameter key to get/set
* Object:
* - param - Query parameter key to get/set
@kamranayub
kamranayub / Transforms.xml
Created February 26, 2012 18:02
MSBuild Inline Task to Transform a Hierarchy of XML Files using XDT Transforms
<!-- This task takes in a XDT transform file and transforms it, following any inheritance chain.
There should be at least one base transform for this to work; otherwise just use Microsoft's
regular TransformXml task. -->
<!-- EXAMPLE USAGE:
<TransformXmlHierarchy
Source="source.xml"
Destination="transformed.xml"
TaskDirectory="path/to/directory/of/Microsoft.Web.Publishing.Tasks" />
-->
<UsingTask