Skip to content

Instantly share code, notes, and snippets.

@developit
developit / factory-loader.md
Created March 25, 2017 18:24
factory-loader

Factory Loader

This is a tiny webpack loader that invokes a given module with another as an argument.

What's that useful for? Dependency Injection! Maybe this is how we can solve the VDOM fragmentation issue.

Example

Here's a library-agnostic VDOM component. Notice that it doesn't import react/preact/inferno/whatever - instead, it takes the VDOM library as an argument.

@fdaciuk
fdaciuk / extract-all-text-plugin.js
Created March 20, 2017 17:58
Webpack extract text even when use dynamic import()
'use strict'
class ExtractText {
constructor (options) {
this.options = options
this.filterFunction = this.getFilterFunction(options)
this.emit = this.emit.bind(this)
}
getFilterFunction (options) {
// Logs all calls to preventDefault / stopPropagation in an user-friendly way
if ( process.env.NODE_ENV !== "production" ) {
(function monkeyPatchEventMethods() {
const logEventMethodCall = (event,methodName) => {
const MinimumMeaninfulSelectors = 3; // how much meaningful items we want in log message
const target = event.target;
const selector = (function computeSelector() {
@bobbytables
bobbytables / build.sh
Created February 18, 2017 15:49
Protocol Buffer build script for multiple folders
#!/usr/bin/env bash
# This script is meant to build and compile every protocolbuffer for each
# service declared in this repository (as defined by sub-directories).
# It compiles using docker containers based on Namely's protoc image
# seen here: https://github.com/namely/docker-protoc
set -e
REPOPATH=${REPOPATH-/opt/protolangs}
CURRENT_BRANCH=${CIRCLE_BRANCH-"branch-not-available"}
@RichardKnop
RichardKnop / accounting.sql
Created January 5, 2017 06:55 — forked from NYKevin/accounting.sql
Basic double-entry bookkeeping system, for PostgreSQL.
CREATE TABLE accounts(
id serial PRIMARY KEY,
name VARCHAR(256) NOT NULL
);
CREATE TABLE entries(
id serial PRIMARY KEY,
description VARCHAR(1024) NOT NULL,
amount NUMERIC(20, 2) NOT NULL CHECK (amount > 0.0),
-- Every entry is a credit to one account...
@assimovt
assimovt / Dockerfile
Last active January 31, 2024 18:30
Dockbit Dev environment
FROM ruby:2.3
MAINTAINER [email protected]
# Install app dependencies
RUN apt-get update -qq && apt-get install -y \
build-essential \
libpq-dev \
unzip \
telnet \
vim \
@jimmycuadra
jimmycuadra / kibana.tmpl.yml
Created November 18, 2016 04:16
Exposing a Kubernetes service (in this example, AWS Elasticsearch Service + Kibana) with an ingress resource an oauth2_proxy.
---
kind: "Template"
apiVersion: "v1"
metadata:
name: "kibana"
objects:
- kind: "Namespace"
apiVersion: "v1"
metadata:
name: "kibana"
@oinopion
oinopion / read-access.sql
Created October 5, 2016 13:00
How to create read only user in PostgreSQL
-- Create a group
CREATE ROLE readaccess;
-- Grant access to existing tables
GRANT USAGE ON SCHEMA public TO readaccess;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO readaccess;
-- Grant access to future tables
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO readaccess;
require 'warden/github'
class SidekiqGithubChecker
def self.registered(app)
app.helpers do
def warden; env['warden'] end
def github_organization_authenticate!(name)
unless warden.user.organization_member?(name)
halt [401, {}, ["You don't have access to organization #{name}"]]
end
# config/initializers/active_model_serializers.rb
ActiveModelSerializers.config.key_transform = :unaltered
ActiveModelSerializers.config.schema_path = 'docs/schema/schemata'
ActiveSupport.on_load(:action_controller) do
require 'active_model_serializers/register_jsonapi_renderer'
end
# Routing constraint:
# Request 'Content-Type' must be 'application/vnd.api+json'