Skip to content

Instantly share code, notes, and snippets.

View jweir's full-sized avatar
🌴
On vacation - foreva

John Weir jweir

🌴
On vacation - foreva
View GitHub Profile
@jweir
jweir / ai
Created November 29, 2023 18:37
Ruby interface to OpenAI
#! /usr/bin/env ruby
# frozen_string_literal: true
require_relative 'ai'
bot = OpenAIChatbot.new(ENV.fetch('OPENAI_API_KEY', nil))
bot.read_input

Migrating X86 Linux development on Intel Mac to Apple Silicon

We have a Ruby application running on Ubuntu x86 Linux. Development is done locally on the developer's machines using Vagrant managed VirtualBox VMs. File synchronization is handled by vagrant rsync. NFS and the built in VirtualBox file sync were not performant.

By coincidence all developers use Macs – they choose their hardware. And they wanted to use new Apple Silicon (Arm 64) machines. These new machines can not emulate X86 hardware with reasonable performance.

# helper function to embed Elm applications
# This does not support defining ports
module ElmHelper
def elm(element_id, elm_app, **flags)
tag.div('', data: { turbo: 'false' }) do
add_elm_global_flags +
tag.div('', id: element_id) +
embed_elm_app(element_id, elm_app, **flags).html_safe
end
end
@jweir
jweir / logs-to-s3.sh
Created October 14, 2019 20:04
Copy log files to S3
for file in `ls access*.gz` ; do
curl -X PUT -d @$file http://localhost:8081/data/logs/$(hostname)/$(date -Idate)/$file
done;
@jweir
jweir / App.elm
Last active March 11, 2023 14:05
Work around for Elm Reactor programWithFlags (elm 0.18)
module App exposing (..)
import Html
type alias Flags =
{ name : String }
type alias Model =
@jweir
jweir / FloatInput.elm
Last active January 23, 2017 03:54
Enable decimal input in elm
module Main exposing (..)
-- solution based on https://groups.google.com/d/msg/elm-discuss/g7X0jTw87Ck/iudNZekGBQAJ by Witold Szczerba
import Html exposing (beginnerProgram, div, button, text)
import Html.Events exposing (onInput)
import Html.Attributes as HA
import String
type alias Model =
@jweir
jweir / select.elm
Created August 9, 2016 21:26
Elm Select
select [onchange ??] [
option [value FILTER_A] [text "Filter a"]
, option [value FILTER_B] [text "Filter b"]
]
@jweir
jweir / stitch.py
Created May 6, 2016 21:48
stitch images in python
"""
First make sure you have the Python Image libraries installed
sudo pip install pillow
Down below you will need to define the absolute path to the images see "dir=..."
Run this by entering
python stitch.py
@jweir
jweir / const_parse.rb
Last active May 2, 2023 21:09
Simple parse to find all constants in a Ruby file
require 'test_helper'
require 'ripper'
# see http://svenfuchs.com/2009/7/5/using-ruby-1-9-ripper
# Only finds contants which are referenced or defined via class
# does not find constants which are defined inline i.e. X=true
class ConstParser < Struct.new(:source)
def consts
consts = []
@jweir
jweir / pipes.js
Last active August 29, 2015 14:28
Naive pipes in javascript
function pipe(src){
var value = src;
return function(){
for(var i = 0; i < arguments.length; i++){
var fn = arguments[i];
value = fn.call(null, value);
}
return value
}