Skip to content

Instantly share code, notes, and snippets.

Avatar

David Wessman davidwessman

View GitHub Profile
@davidwessman
davidwessman / update-next.yml
Last active Jan 14, 2021
Action to upgrade Gemfile.next.lock
View update-next.yml
name: Update next
on:
pull_request:
paths:
- "Gemfile.lock"
jobs:
update:
runs-on: ubuntu-20.04
View tap_reporter.rb
module Minitest
module Reporters
# Based on https://github.com/kern/minitest-reporters/blob/master/lib/minitest/reporters/progress_reporter.rb
# Tries to adhere to https://testanything.org/tap-specification.html
class TapReporter < DefaultReporter
def report
super
puts("TAP version 13")
puts("1..#{tests.length}")
View .circleci-config.yml
version: 2
jobs:
build:
working_directory: ~/mowers
docker:
- image: circleci/ruby:2.4.1-node
environment:
PGHOST: 127.0.0.1
PGUSER: mower
RAILS_ENV: test
View app-assets-javascript-calendars.js
const calendar = {
initialize() {
const calendars = document.getElementsByClass('fullcalendar');
Array.from(calendars).forEach(function(cal) {
const place = cal.dataset.place;
cal.html(''); // Remove any previous calendar
cal.fullCalendar({
eventSources: [{ url: '/events/feed.json?place=' + place }],
other_options:...
});
@davidwessman
davidwessman / Systemd for Sidekiq
Created Jun 14, 2017
Systemd setup for Sidekiq with Capistrano
View Systemd for Sidekiq
# Setup Sidekiq for rails on Debian
# This setup uses systemd to start via terminal but also via the deploy system Capistrano.
# The reload-task will not actually reload the service, but is used to prepare Sidekiq for shutdown
# There exists two services to allow for both staging and production environment.
# The application uses different redis databases by using different numbers to connect,
# i.e. localhost:6379/0 or :6379/1, which are set in each applications environment variables.
# Any questions about the configuration? Hit me up
# David Wessman, Lund , 2016-09-07, david@wessman.co
View Marko.rb
class OrderItem < ActiveRecord::Base
belongs_to :product, required: true
belongs_to :order, required: true
has_one :user, through: :order
validates :quantity, presence: true, numericality: { only_integer: true, greater_than: 0 }
validate :user_limited
before_save :finalize
def unit_price
View database.yml
development:
adapter: mysql2
encoding: utf8
database: db/app_development
username: root
password:
host: localhost
production:
adapter: mysql2
@davidwessman
davidwessman / black_and_white.py
Last active Nov 23, 2015
Black and white plots in Python.
View black_and_white.py
def setAxLinesBW(ax):
"""
Take each Line2D in the axes, ax, and convert the line style to be
suitable for black and white viewing.
"""
MARKERSIZE = 3
COLORMAP = {
'b': {'marker': None, 'dash': (None,None)},
'g': {'marker': None, 'dash': [5,5]},
@davidwessman
davidwessman / export_example.m
Created Nov 16, 2015
Export Matlab figure as PDF
View export_example.m
% This needs to be set to be able to print
fig = figure;
% If you want multiple plots in the figure
hold on;
I = 0:1:9;
blue = [0, 0.048, 0.143, 0.129, 0.236, 0.333, 0.479, 0.512, 0.582, 0.678];
red = [0, 0.095, 0.106, 0.171, 0.156, 0.227, 0.270, 0.300, 0.366, 0.384];
plot(I, blue,'+b')
@davidwessman
davidwessman / import_matlab.tex
Last active Dec 10, 2015
Import Matlab to LaTeX
View import_matlab.tex
% https://www.ctan.org/pkg/listings
\usepackage[procnames]{listings}
\usepackage{color} %red, green, blue, yellow, cyan, magenta, black, white
\definecolor{mygreen}{RGB}{28,172,0} % color values Red, Green, Blue
\definecolor{mylilas}{RGB}{170,55,241}
% Python style for highlighting
\newcommand\matlabstyle{\lstset{
language=Matlab