Skip to content

Instantly share code, notes, and snippets.

Jan Paul Posma janpaul123

Block or report user

Report or block janpaul123

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
janpaul123 /
Created Jan 7, 2020
Read an "input.bag" ROS bag with messages stored in arbitrary order, and write to "output.bag" ordered by receive time (required by Webviz to read)
import rosbag
with rosbag.Bag('output.bag', 'w') as outbag:
for topic, msg, t in rosbag.Bag('input.bag').read_messages():
outbag.write(topic, msg, t)
janpaul123 / FastScrollComponent-test.js
Created May 18, 2018
Copyright: Remix Software; License: MIT
View FastScrollComponent-test.js
/* eslint-disable react/prop-types */
import React from 'react';
import ReactDOM from 'react-dom';
import ReactTestUtils from 'react-dom/test-utils';
import FastScrollComponent from './FastScrollComponent';
describe('<FastScrollComponent>', function() {
const setupComponent = ({ cacheWhenNotVisible = false, height = 100 }) => {
// eslint-disable-line react/prop-types
const rowHeight = 25;
janpaul123 / permutations.js
Created Feb 12, 2018
Number of unique corners for given color / dot schemes
View permutations.js
const uniq = require('lodash/uniq');
function permutations(n, colors, arr) {
if (!n) return [arr];
if (!arr) arr = [];
let ret = [];
for (let i = 0; i < colors; i++) ret = ret.concat(permutations(n - 1, colors, arr.concat([i])));
return ret;
janpaul123 / SimpleBlobDetector.js
Last active Mar 1, 2020
OpenCV SimpleBlobDetector port to OpenCV.js
View SimpleBlobDetector.js
// Port of
// But with special `faster` option which has slightly different semantics,
// but is a whole bunch faster.
function diff(v1, v2) {
if (v1.x !== undefined) return { x: v1.x - v2.x, y: v1.y - v2.y };
return, index) => value - v2[index]);
function norm(vector) {
janpaul123 / models_helper.rb
Last active Dec 27, 2017
Test helper for changing counts
View models_helper.rb
module ModelsHelper
# Expects that only the passed in models have counts that change. For this we
# look at all ActiveRecord models, and store their counts.
# Example: `expect_only_counts_changing(Trip: -1) { Trip.first.delete }`
# This gives stronger guarantees against future models being affected
# unexpectedly by other parts of the code base.
def expect_only_counts_changing(expected_changes)
previous_counts = ModelsHelper.counts
View apply_diffs_to_map_document_data.rb
module Interactors
module ApplyDiffsToMapDocumentData
def, diffs:)
return if diffs.empty?
sql = <<-SQL
UPDATE maps SET document_data =
#{ { 'jsonb_set(' }.join('')}
#{ { |diff, i| ", '{#{diff[:path].join(',')}}', :value_#{i})" }.join('')}
janpaul123 / identity_of_model.rb
Created Sep 29, 2017
Fun recursive function to test if things like copying deep data structures work correctly. Done with @boconnell at @remix.
View identity_of_model.rb
def identity_of_model(model, global_excluded=['id', 'created_at', 'updated_at', 'deleted_at'])
excluded_columns = + global_excluded
identity = model.attributes.except(*excluded_columns)
model.class.reflect_on_all_associations(:has_many).sort_by(&:name).each do |ref|
identity[] = model.send(
model.class.reflect_on_all_associations(:has_and_belongs_to_many).sort_by(&:name).each do |ref|
identity["#{}_counts"] = model.send(
janpaul123 / pronto.rb
Created Apr 8, 2017
Custom pronto matcher
View pronto.rb
#!/usr/bin/env ruby
require 'pronto'
module Pronto
class RegexWarnings < Runner
# Matchers arguments: path, text, addition, first_changed_line
def matchers
->(path, text, addition, _) { path.match(/\.js$/) && text.include?('http:') && addition } =>
View monorepo-tester.js
#!/usr/bin/env node
const commandLineArgs = require('command-line-args');
const { existsSync, writeFileSync } = require('fs');
const { execSync } = require('child_process');
const jmerge = require('junit-merge/lib');
const path = require('path');
const syncRequest = require('sync-request');
// Copyright Jan Paul Posma, 2017. Licensed under MIT license.
janpaul123 / .diffux_ci-new.yaml
Created Jul 6, 2016
Diffux on CircleCI sketch
View .diffux_ci-new.yaml
- http://localhost:8080/diffux.js # For convenience, for use with webpack server. Is ignored on CircleCI.
- diffux-new.js
snapshots_folder: ./diffux_snapshots
You can’t perform that action at this time.