Skip to content

Instantly share code, notes, and snippets.

View mikz's full-sized avatar

Michal Cichra mikz

View GitHub Profile
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />
<meta name="generator" content="AsciiDoc 8.6.9" />
<title>giteveryday(7)</title>
<style type="text/css">
/* Shared CSS for AsciiDoc xhtml11 and html5 backends */
@mikz
mikz / gist:df306f511d40017c5375
Last active August 29, 2015 14:09
Messed up handling of keyword arguments splat in ruby
class Result
attr_reader :object, :options
def initialize(object = nil, **options)
@object = object
@options = options
end
end
args = { value: true }
@mikz
mikz / gist:4ce4307329095114b109
Last active August 29, 2015 14:06
nginx ssl CApath
--- bundle/nginx-1.7.4/src/event/ngx_event_openssl.c.orig 2014-09-10 23:33:09.000000000 +0200
+++ bundle/nginx-1.7.4/src/event/ngx_event_openssl.c 2014-09-10 23:33:49.000000000 +0200
@@ -498,6 +498,7 @@
SSL_CTX_set_verify_depth(ssl->ctx, depth);
if (cert->len == 0) {
+ SSL_CTX_set_default_verify_paths(ssl->ctx);
return NGX_OK;
}

The problem

curling through web services can be tedious without some basic pretty printing. Let's see how easy it is to create aliases for pretty printing json/xml formats with Python's pygments library and xmllint/jsonp.

The Solution

alias xml='xmllint --format - | pygmentize -l xml -O encoding=utf8'
alias json='jsonpp | pygmentize -l json -O encoding=utf8''

Then just curl http://wservice.viabicing.cat/getstations.php\?v\=1 | xml or curl https://b83c5a5e-d575fbfbad2f.my.apitools.com | json to get nice XML/JSON output.

local geo = {}
-- ~radius of the earth in miles
geo.radius = 3958.75587
-- miles between point a and point b
function geo.distance(lat1, lng1, lat2, lng2)
local rlat = lat1*math.pi/180;
local rlng = lng1*math.pi/180;
local rlat2 = lat2*math.pi/180;
local rlng2 = lng2*math.pi/180;
@mikz
mikz / docker_processes.rb
Last active August 29, 2015 13:57
sensu plugin to get stats from docker containers
#!/usr/bin/env ruby
require 'rubygems' if RUBY_VERSION < '1.9.0'
require 'sensu-plugin/metric/cli'
require 'socket'
require 'pathname'
require 'sys/proctable'
class DockerContainerMetrics < Sensu::Plugin::Metric::CLI::Graphite
@mikz
mikz / docker-namesgenerator.rb
Created March 17, 2014 19:58
Fetches awesome namesgenerator from docker & runs it in ruby.
require 'open-uri'
class NamesGenerator
def self.load
go = open('https://raw.github.com/dotcloud/docker/master/pkg/namesgenerator/names-generator.go')
left, right = go.read.scan(/\[\.\.\.\]string{(?<strings>.+)}/)
left = left.first.scan(/"(.+?)"/)
# flat api params like: name=John&surnname=Doe
POST '/api/user', name: 'John', surname: 'Doe'
# nested api params like: user[name]=Jack&user[surname]=Xzbit
POST '/api/user', user: { name: 'Jack', surname: 'Xzbit' }
# how to get only params that are related to the model?
# imagine case:
@mikz
mikz / alias.sh
Created November 15, 2012 16:21
Tiny script to run ruby files or run all files in directory (usefull for tests)
alias rt="ruby -Itest -I. -e \"alias rt="ruby -Itest -I. -e \"require'pathname';P=Pathname;ARGV.map{|a|p=P.new(a);next unless p.exist?;p.directory?? P.glob(p.join('**/*.rb')):p}.flatten.compact.uniq.each{|p|require p.expand_path}\""\""
@mikz
mikz / calendar.rb
Created October 12, 2012 10:09
GeekTool MacRuby calendar (10.8 only)
#!/Users/mikz/.rvm/rubies/macruby-0.12/bin/ruby
# coding: utf-8
def colorize(text, color_code)
"\e[0;#{color_code}m#{text}"
end
def black(text=""); colorize(text, 30); end
def red(text=""); colorize(text, 31); end
def green(text=""); colorize(text, 32); end