Skip to content

Instantly share code, notes, and snippets.

View markjlorenz's full-sized avatar

Mark Lorenz markjlorenz

View GitHub Profile
# Starts a BLE service, that allows central devices to register for notifications.
# When a button attached to GPIO-32 is pressed, the counter is incremented, and
# registerd central devices are notified.
#include <BLEDevice.h>
#include <BLEServer.h>
#include <BLEUtils.h>
#include <BLE2902.h>
#include "driver/rtc_io.h"

Run the container, with the gem files living on the host filesystem

docker run -it --rm \
  --volume "$PWD":/app \
  --workdir /app \
  --env "BUNDLE_PATH=.gems" \
  --link "earnings-calls-database"  \
  soodesune/ruby-rails:2.3.1-alpine sh
@markjlorenz
markjlorenz / jenkins-api-start-and-monitor-a-build
Created July 23, 2016 18:11
Start a job with the Jenkins API and monitor it's console output
#! /usr/bin/env bash
JENKINS_URL="localhost:8080"
JOB_NAME="YourJobName
USER_NAME="api"
USER_TOKEN="f6706YOURUSERTOKENd2c51"
QUEUE_URL=$(curl --silent "http://${JENKINS_URL}/job/${JOB_NAME}/build" \
--user "${USER_NAME}:${USER_TOKEN}" \
--data "token=${JOB_TOKEN}" -XPOST \
@markjlorenz
markjlorenz / simple-exec-with-docker-remote-api.sh
Created July 23, 2016 16:05
Using the exec command with the docker API, and capturing output
#! /usr/bin/env bash
# Create the container with a long running process. If PID1 exists before
# we send the exec commands, they will fail because the container is not running
#
CONTAINER_NAME="TEST-`uuidgen`"
curl --silent --unix-socket /var/run/docker.sock "http:/containers/create?name=${CONTAINER_NAME}" -XPOST \
-H "Content-Type: application/json" \
-d '{
"Image": "ruby:latest",
@markjlorenz
markjlorenz / colors.sh
Created September 5, 2015 22:58
cycle text through some different colors
while true; do for i in 30 31 32 33 34 35 36; do echo -en '\033[1;'$i"m" "Hi Charlotte & Blaise"; sleep 0.1; done; echo -en '\033[1;0m'; done
@markjlorenz
markjlorenz / better_spec_through_block_arguments.markdown
Last active August 29, 2015 14:03
Improving spec clarity though with block arguments.

Better Specs Through Block Arguments

Me, fixing my specs c.333 BC

Me, fixing my specs c.333 BC

let considered harmful

If not used carefully, the powerful lazy-let construct in Rspec can quickly turn your specs into a spaghetti monster throwing Gordian knots.

When used correctly, let is the best thing ever.

@markjlorenz
markjlorenz / first_and_only.rb
Last active August 29, 2015 14:03
First and only
module Enumerable
def first_and_only!
fail(FirstAndOnly::LengthNotOne, count) if first(2).count != 1
first
end
module FirstAndOnly
LengthNotOne = Class.new(StandardError)
end
end
@markjlorenz
markjlorenz / 1.markdown
Last active August 29, 2015 14:02
One reason that Ruby's documentation isn't great.

One Reason Ruby's Docs Aren't Great

If you followed those links, you might be thinking that I screwed them up. I didn't. Looke closely, and you'll notice that the Fixnum#== docs are actaully repeated twice. Neat.

You might think that's a bug. It's not.

Let's see why:

@markjlorenz
markjlorenz / 1_nicholas.txt
Created June 23, 2014 02:11
_why responds on the ruby mailing list
Subject: Ruby for Highschoolers?
From: Nicholas Evans <OwlManAtt OwlManAtt.com>
Date: Mon, 12 Jun 2006 01:55:39 +0900
Howdy list,
I'm a highschool student with a very high chance of ending up
student-teaching the Programming I course during the 07-08 schoolyear.
This year was the first year for the course, and Scheme was used.
However, I've been talking to the teacher about Ruby, suggesting that