Skip to content

Instantly share code, notes, and snippets.

View jberndsen's full-sized avatar

Jeroen jberndsen

View GitHub Profile
@jberndsen
jberndsen / with-apollo.tsx
Created January 17, 2020 13:16
with-apollo.tsx
import React from 'react';
import Head from 'next/head';
import { ApolloProvider } from '@apollo/react-hooks';
import { ApolloClient } from 'apollo-client';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { HttpLink } from 'apollo-link-http';
import fetch from 'isomorphic-unfetch';
let browserClient = null;
set -e
CURRENT_BRANCH=$(git branch | grep \* | cut -d ' ' -f2)
if [[ "$CURRENT_BRANCH" == "develop" ]]
then
git pull
REL=$(npm --no-git-tag-version version minor | sed 's/^v//')
git checkout -b release/$REL
git add package.json package-lock.json
@jberndsen
jberndsen / ioc.tsx
Created October 10, 2019 09:40
Simple DI functionality using React Context API and hooks
import React, { useContext } from 'react';
declare global {
interface Window {
__DI_CONTAINER__: Container;
}
}
type Newable<T> = new (...args: unknown[]) => T;
@jberndsen
jberndsen / bootstrapper.js
Created November 4, 2017 11:44
Run AngularJS initialization logic before main AngularJS app
// define the module of the bootstrap app
var bootstrapModule = angular.module('bootstrapModule', []);
// the bootstrap service loads the config and bootstraps the specified app
bootstrapModule.factory('bootstrapper', function ($q, $http) {
return {
bootstrap: function (appName) {
var deferred = $q.defer();
// do initial loading here
@jberndsen
jberndsen / filterBy.filter.ts
Created September 4, 2017 11:24
Angular 2+ pipe to filter items based on value of a single prop
import {Pipe, PipeTransform} from '@angular/core';
@Pipe({
name: 'filterBy'
})
export class FilterByFilter implements PipeTransform {
transform(list, arg: string) {
if (!list) {
return [];
}
@jberndsen
jberndsen / observables.js
Created March 17, 2017 15:29
observables introduction lesson
// BEFORE YOU start
// npm init -y
// npm install --save node-fetch rx
const Rx = require('rx');
const fetch = require('node-fetch');
// 1. create a stream based on an array using Rx.Observable.fromArray
const list = [1, 2, 3, 4, 5]; // list is a regular Array
const streamA = Rx.Observable.fromArray(list); // stream is an Observable, it will emit all values immediately
@jberndsen
jberndsen / Startup.cs
Created March 15, 2017 13:39
OWIN pipeline breakpoint
app.Use(async (context, next) =>
{
await next.Invoke();
});
@jberndsen
jberndsen / promise.js
Last active August 7, 2019 04:56
exercises to learn promises
// BEFORE YOU start
// npm init -y
// npm install --save node-fetch
const fetch = require('node-fetch');
// INTRO
// Javascript is single threaded, meaning that two bits of script cannot run at the same time.
// Doing something which takes some time (a costly algorithm, a back-end call) causes everything else to halt
// until it completes. In browsers, this often means the UI becomes non-responsive,
// because the rendering of the screen is blocked.
<?php
/*
Plugin Name: Tools Loader
Description: A plugin to load project-specific AngularJS snippets (mini apps) using shortcodes.
Version: 0.1 alpha
Author: Jeroen Berndsen
Author URI: http://www.jberndsen.nl
*/
// load requirejs
@jberndsen
jberndsen / storage.service.ts
Created March 3, 2017 09:37
Simple Angular 2+ web storage service
import {Injectable} from '@angular/core';
import {window} from '@angular/platform-browser/src/facade/browser';
@Injectable()
export class StorageService {
// todo: make these configurable, have a look at
// https://github.com/phenomnomnominal/angular-2-local-storage/
private prefix = 'my_ng2_app';
private storageType: 'sessionStorage' | 'localStorage' = 'sessionStorage';
private storage: any;