Skip to content

Instantly share code, notes, and snippets.

Avatar

Jason Walton jwalton

View GitHub Profile
@jwalton
jwalton / pdf2jpg2pdf.sh
Created May 24, 2021
Convert a PDF of JPGs to JPGs, recompress them, and then back to PDF.
View pdf2jpg2pdf.sh
# Launch a fresh VM
docker run --rm -it -v `pwd`:/mount ubuntu
# Extract PDF to JPGs
cd /mount
apt-get update
apt-get install poppler-utils
pdfimages -j file.pdf fileprefix
mkdir extract
mv *.jpg extract
View main_benchmark_test.go
package main
import (
"testing"
"github.com/fatih/color"
"github.com/jwalton/gchalk"
"github.com/logrusorgru/aurora"
"github.com/mgutz/ansi"
"github.com/muesli/termenv"
@jwalton
jwalton / prefixFormat.ts
Created Jun 24, 2020
Winston Formatters
View prefixFormat.ts
import * as path from 'path';
export interface PrefixFormatOptions {
basepath?: string;
}
/**
* This is a debug format, used to prefix the message with tags and filenames.
*
* This copies values to `message`, and strips values out of the `info` so
@jwalton
jwalton / useWhyRender.tsx
Created Jun 18, 2020
A react hook to figure out why a component is rendering
View useWhyRender.tsx
/* tslint:disable:no-console */
import ld from 'lodash';
import React from 'react';
/**
* Use this hook to figure out why a React component is re-rendering.
* It will log if any properties in `props` have changed. You should
* also pass any state variables into `props` as well.
*
View logger middleware.ts
import * as http from 'http';
import onFinished from 'on-finished';
/**
* Create a middleware that logs all requests.
*
* @param log - Logger to log to.
* @param [options] - Options.
* @param [options.excludeUrls] - An array of endpoints which should not be
@jwalton
jwalton / index.ts
Created Mar 29, 2019
webpackMiddleware
View index.ts
import * as express from 'express';
import { createRouter } from './routes';
import translations from './translations';
const WEBPACK_AVAILABLE = (() => {
try {
require('webpack');
return true;
} catch (err) {
return false;
View archive.sh
#!/usr/bin/env bash
# Adapted from http://scottwb.com/blog/2012/07/14/merge-git-repositories-and-preseve-commit-history/
#
# This is a script for archiving old private repos into an `attic` repo. To use, fill in the `ACCOUNT`
# variable below, then add this script to your "attic" repo, then just `./archive.sh [reponame]` from
# your cloned attic repo. This will take the contents of "reponame" and copy them into a subdirectory in
# attic named "reponame", preserving history. Note that the original repo is not modified in any way
# (we clone it to /tmp/reponame and don't push anything) and this script doesn't auto-push your attic
# repo, so if it all goes horribly wrong, it's very easy to recover.
View BigImage.md

A Dashing widget which shows an image.

To use, in your dashboard.erb file:

<li data-row="1" data-col="1" data-sizex="3" data-sizey="2">
  <div data-id="picture" data-view="BigImage" data-image="http://i.imgur.com/JycUgrg.jpg"
    style="background-color:transparent;"
    data-max="true"
  ></div>
</li>
@jwalton
jwalton / FlyingWidgets.md
Last active Apr 1, 2021
CSS3 Transitions for Dashing Dashboards
View FlyingWidgets.md

Flying Widgets adds CSS3 transitions to your dashboard, allowing you to cycle through multiple widget sets on a single TV without page reloads, using stylish CSS3 transitions. You can even still re-order your widgets and save their locations!

Note that sinatra-cyclist is a potential alternative if the machine you use to display your dashboards is lacking in graphics horsepower.

To use, put this file in assets/javascripts/cycleDashboard.coffee. Then find this line in application.coffee:

    $('.gridster ul:first').gridster
@jwalton
jwalton / OC Transpo for Dashing.md
Last active Mar 26, 2019
OC Transo widget for Dashing
View OC Transpo for Dashing.md

Fetches times for the next buses at a given OC Transpo stop.

Add the following to your gemspec:

gem 'octranspo_fetch', '>= 0.0.4'

Screen Shot

Then configure the constants at the top of oc_transpo.rb.