Skip to content

Instantly share code, notes, and snippets.

@balexand
balexand / sign.ex
Created March 17, 2024 00:18
Sign S3 GET request in Elixir
:aws_signature.sign_v4_query_params(
s3_config.access_key_id,
s3_config.secret_access_key,
s3_config.region,
"s3",
:erlang.universaltime(),
"GET",
"https://#{s3_config.bucket}.s3.#{s3_config.region}.amazonaws.com/#{asset.key}",
body_digest: "UNSIGNED-PAYLOAD"
)
@balexand
balexand / svg-bbox.js
Last active December 5, 2019 22:45
svg bbox
var svg = document.getElementsByTagName("svg")[0];
var bbox = svg.getBBox();
[bbox.x, bbox.y, bbox.width, bbox.height].join(" ");
@balexand
balexand / README.md
Last active August 11, 2016 20:25 — forked from mbostock/.block

Forked from this, but added slider.

@balexand
balexand / gist:6767504
Last active February 21, 2016 17:41
Load data onto Garmin from Google Earth KML file using gpsbabel
# add the -t option for tracks
gpsbabel -t -i kml -f Telluride.kml -o garmin -F usb:
# To get Caltopo tracks to show up in Backcountry Navigator App, convert the KML using gpsbabel
gpsbabel -i kml -f from_cal_topo.kml -o gpx -F to_app.gpx
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazon.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>https://tracker-dvd.ufcfit-one.com</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
@balexand
balexand / sentry.cpp
Created March 23, 2013 19:52
Makes an Arduino robot pace back and forth.
int MOTOR_A_BRAKE = 9;
int MOTOR_A_SPEED = 3;
int MOTOR_A_DIR = 12;
int MOTOR_B_BRAKE = 8;
int MOTOR_B_SPEED = 11;
int MOTOR_B_DIR = 13;
void setup() {
pinMode(MOTOR_A_SPEED, OUTPUT);
@balexand
balexand / gem-reset.rb
Last active December 14, 2015 07:49 — forked from nixpulvis/gem-reset
#!/usr/bin/env ruby
# Remove all gems EXCEPT defaults :)
`gem list -d`.split(/\n\n^(?=\w)/).each do |data|
match = data.match(/(?<name>([^\s]+)) \((?<versions>.*)\)/)
name = match[:name]
versions = match[:versions].split(', ')
if match = data.match(/^.*\(([\d\.]*),? ?default\): .*$/)
next if match[1].empty? # it's the only version if this match is empty
@balexand
balexand / gist:4958397
Created February 15, 2013 03:34
create cropped animated gif using image magick convert command
convert -delay 200 -loop 0 -crop 200x200+0+0 +repage *.png animated.gif
@balexand
balexand / iptables.sh
Last active December 11, 2015 18:59
iptables
#!/bin/bash
### BEGIN INIT INFO
# Provides: iptables
# Required-Start: $syslog
# Required-Stop: $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Firewall
### END INIT INFO
@balexand
balexand / xip_hack.rb
Created June 8, 2012 06:23
xip.io request hack
if Rails.env.development?
class XipIoMiddleware
def initialize(app)
@app = app
end
def call(env)
%w{HTTP_HOST SERVER_NAME SERVER_ADDR HTTP_X_FORWARDED_HOST}.each do |key|
env[key] = env[key].sub(/myapp\.\d+\.\d+\.\d+\.\d+\.xip\.io/, "myapp.dev") if env[key].present?
end