Skip to content

Instantly share code, notes, and snippets.

@vangorra
vangorra / muggins_solver.html
Last active Nov 28, 2019
Provides all possible solutions for the dice game Muggins.
View muggins_solver.html
<html>
<head>
<title>Muggins Solver</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
</head>
<body>
<div id="root"></div>
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.15/lodash.min.js"></script>
@vangorra
vangorra / gql2ts.sh
Last active Feb 27, 2019
Rudimentary graphql to typescript definition generator. Accepts a graphql schema file (not json, nor js) and converts it to typescript defs.
View gql2ts.sh
#!/usr/bin/env bash
cat "$1" \
| sed -r 's/^(\s*)#/\1\/\//' \
| sed -r 's/!//g' \
| sed -r 's/^input /export interface /g' \
| sed -r 's/^enum /export enum /g' \
| sed -r 's/^type /export interface /g' \
| sed -r 's/^union /export type /g'\
| sed -r 's/^schema /export interface schema /g' \
| sed -r 's/^(\s+[a-zA-Z0-9_-]+\s*)\([^\)]+\)(\s*:\s*)/\1\2/g' \
@vangorra
vangorra / start_program_loop.bat
Last active May 5, 2016
bat (batch) script for running a program only after the network is active. This is great for replacing the default (explorer.exe) interface with a single app that will operate as a kiosk. In the code, we are starting procare in kiosk mode but this can easily be some other software. For my own reference, to change the default UI for a user. Run m…
View start_program_loop.bat
ECHO OFF
IF NOT EXIST "C:\Program Files\Procare\Client\CheckInNet.exe" (
echo Procare checkin client is not installed. Closing in 120 seconds...
timeout /T 120
) ELSE (
:loop
echo -------------
echo Checking if procare should be started. Checking if network is available...
View BootstrapWindowSizeProvider.ts
import {Provider, NgZone, Injectable} from 'angular2/core';
/**
* Provider for providing bootstrap style window sizes to angular2 templates. While bootstrap provides
* visible-sm, visible-md, etc. These classes do not prevent angular2 from rendering the template.
* This behaviour is negligible on a desktop, but on mobile devices, that extra rending can increase
* the overall render time.
* This provider makes bootstrap style window sizes available to your template, so you can choose
* which parts of your template render on specific screen sizes.
*/
@vangorra
vangorra / AbstractComponent.ts
Created Mar 20, 2016
An abstract component that adds some meta-data about when subscriptions are completed.
View AbstractComponent.ts
import {MeteorComponent} from 'angular2-meteor';
/**
* An abstract class that performs a lot of boiler plate functionality.
*/
export default class AbstractComponent extends MeteorComponent {
/**
* True when all the subscriptions are ready.
*/
isReady : boolean;
View BootstrapWindowSizeProvider.ts
import {Provider, NgZone, Injectable} from 'angular2/core';
/**
* Provider for providing bootstrap style window sizes to angular2 templates. While bootstrap provides
* visible-sm, visible-md, etc. These classes do not prevent angular2 from rendering the template.
* This behaviour is negligible on a desktop, but on mobile devices, that extra rending can increase
* the overall render time.
* This provider makes bootstrap style window sizes available to your template, so you can choose
* which parts of your template render on specific screen sizes.
*/
@vangorra
vangorra / compiler-ts.js
Last active Feb 15, 2016
A template Meteor package. The source can be typescript and the tests must be js. The benefit here is you can write your source in Typescript and still test the source.
View compiler-ts.js
// This is our package's very own build plugin. It is intended to only transpile specific files.
'use strict';
// Filenames should be a list of the typescript files you want to transpile in your package.
Plugin.registerCompiler(
{
extensions: [],
filenames: ['lib.ts']
}, function() {
return new TsCompiler()
@vangorra
vangorra / gist:8088a3ff4355d6124765
Last active Aug 29, 2015
This script is intended to be used with the Dagger dependency injection framework for android (http://square.github.io/dagger/). While Dagger does a great job detecting errors at compile-time, it can only validate the classes you provide in the injects option of your class. This shell script will scan your source for any class that uses the @Inject
View gist:8088a3ff4355d6124765
TMP_SRC_PATH="src/main/java"; grep -rin --include '*.java' '@Inject' "$TMP_SRC_PATH" | cut -d':' -f1 | sed -E 's@.*/@@' | cut -d'.' -f1 | sort | uniq | xargs -I'{}' grep -rinE --include '*.java' '( extends {}| class {} )' src/main/java | sort | uniq | cut -d ':' -f1 | sed "s@$TMP_SRC_PATH@@" | sed 's@/@.@g' | sed 's/.java$/.class,/' | sed 's/^.//'
@vangorra
vangorra / gist:c1383c355ce8fe56adf8
Last active Jul 28, 2016
Android Gradle Elastic Dependencies - How to configure gradle to dynamically switch between artifact (aar) and project dependencies while still allowing Android Studio to resolve those dependencies correctly.
View gist:c1383c355ce8fe56adf8
/*
Android Gradle Elastic Dependencies - How to configure gradle to dynamically switch between artifact (aar) and project dependencies while still allowing Android Studio to resolve those dependencies correctly.
So at work I have a big central library, let's call it the "library". The library is used over and over in several different projects. For my automated builds, I have the projects use the maven published aar file and compile against that. This is very useful as the aar used on the build server is blessed as stable and we don't need to compile that code unecessarily. While that works well for a build server, it is a pain when activley developing a specific project.
The problem that occurs is if I need to make a change to my "library", I have to make the change, compile the aar, copy the aar to my project, compile the project and see if my change worked. That workflow is riduculously slow.
Ultimatley, my configuration ends up using the local library source if it is available but will fall back onto th
@vangorra
vangorra / BinaryReaderDotNet
Created Mar 10, 2014
A simple java class that is capable of parsing files generated by .net's BinaryWriter class. Some methods are not implemented as I did not have any use for them.
View BinaryReaderDotNet
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
/**
* A java class that is capable for parsing .net BinaryWriter encoded files.
* Some methods are not implemented as I have not need for them. Enjoy!
* @author robbiev