Skip to content

Instantly share code, notes, and snippets.

View configurator's full-sized avatar

Dor Kleiman configurator

View GitHub Profile
@configurator
configurator / UltimateTestCase.cs
Created October 10, 2014 00:32
100% test coverage is easy. Making it useful is practically impossible.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
namespace Misadonet.Server.Test {
class UltimateTestCase {
public void Run() {
@configurator
configurator / gist:cd0cb436e43001b9cab4
Created October 15, 2014 22:41
ErrorDiffusion dithering using the Sierra Matrix
/// <summary>
/// See http://en.wikipedia.org/wiki/Floyd-Steinberg_dithering for algorithm details.
/// The matrix used is Sierra [/32]:
/// x 5 3
/// 2 4 5 4 2
/// 2 3 2
/// </summary>
protected static Bitmap ErrorDiffusion(System.Drawing.Image bitmap) {
const double limit = 0.5;
var errors = new ErrorArray(bitmap.Width, bitmap.Height);
@configurator
configurator / 0_reuse_code.js
Last active August 29, 2015 14:16
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@configurator
configurator / fizzbuzz.hs
Created December 14, 2013 16:32
FizzBuzz in Haskell
import Control.Applicative
options = [(3, "Fizz"), (5, "Buzz")]
collect :: [(Integer, String)] -> Integer -> String
collect [] x = ""
collect ((divisor,string):rest) x
| x `mod` divisor == 0 = string ++ collect rest x
| otherwise = collect rest x
@configurator
configurator / gist:5ca2b928c9c82827c6a734f690b28c04
Created June 1, 2017 17:16
When git gc does exactly the opposite of what you expect
user@PENSIVE ~ $ du -sh *-web/.git/objects
42M 2-paystream-web/.git/objects
57M 3-paystream-web/.git/objects
73M 4-paystream-web/.git/objects
8.1M paystream-web/.git/objects
user@PENSIVE ~ $ for i in *web; do pushd $i; git gc; popd; done
~/2-paystream-web ~
Counting objects: 171965, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (33235/33235), done.
<html>
<head>
<title>Balls.</title>
<meta name="viewport" content="width=device-width" />
<style>
html, body {
width: 100vw;
height: 100vh;
margin: 0;
display: flex;
@configurator
configurator / Dockerfile
Created March 29, 2018 20:30
UPX in Docker breaks Go app
# Build app
FROM golang as builder
COPY . /build
RUN cd /build && CGO_ENABLED=0 go build -ldflags='-s -w' app.go
# Compress
FROM lalyos/upx as compressor
COPY --from=builder /build/app /compress/
RUN ["upx", "/compress/app"]
@configurator
configurator / component.jsx
Created November 3, 2019 09:22
Using components that require a loaded script using react-load-script
import React from 'react';
import Loader from './loader';
const drawChart = (data, div) => {
// omitted
// Can use the loaded script safely
}
export default ({data}) => (
<Loader>
@configurator
configurator / reserve-proxy.js
Created March 23, 2020 13:35
A basic reverse proxy in node.js
// This reverse proxy is for local development only
const express = require("express");
const proxy = require("express-http-proxy");
const app = express();
const proxyPort = 8000;
const webpackPort = 8080;
app.use("/", proxy(`http://localhost:${webpackPort}`));
@configurator
configurator / header.bash
Created July 16, 2020 14:41
Bash header for safer code
#!/bin/bash
set -e # exit on error
set -u # error on undefined variable
set -o posix # errors in $() expressions propagate outwards
set -o pipefail # errors in a pipeline will propagate outwards
# set -e
# Any command returning a nonzero code will exit the script
# If you need to run a command that may file, use it either in `if` expressions, or part of an `or` expression such as `command || true`