Skip to content

Instantly share code, notes, and snippets.

View kbrock's full-sized avatar

Keenan Brock kbrock

View GitHub Profile
@staaldraad
staaldraad / awk_netstat.sh
Last active April 3, 2024 07:01
AWK to get details from /proc/net/tcp and /proc/net/udp when netstat and lsof are not available
# Gawk version
# Remote
grep -v "rem_address" /proc/net/tcp | awk '{x=strtonum("0x"substr($3,index($3,":")-2,2)); for (i=5; i>0; i-=2) x = x"."strtonum("0x"substr($3,i,2))}{print x":"strtonum("0x"substr($3,index($3,":")+1,4))}'
# Local
grep -v "rem_address" /proc/net/tcp | awk '{x=strtonum("0x"substr($2,index($2,":")-2,2)); for (i=5; i>0; i-=2) x = x"."strtonum("0x"substr($2,i,2))}{print x":"strtonum("0x"substr($2,index($2,":")+1,4))}'
# No Gawk
# Local
grep -v "rem_address" /proc/net/tcp | awk 'function hextodec(str,ret,n,i,k,c){
@durandom
durandom / extract_ovirt.sh
Created May 9, 2017 18:29
extract a provider
#!/usr/bin/env bash
~/src/scratch/manageiq/extract_provider_gem.sh \
-n ovirt \
-d "app/models/manageiq/providers/redhat spec/models/manageiq/providers/redhat spec/vcr_cassettes/manageiq/providers/redhat" \
-l \
-e ~/src/manageiq \
-r \
-g ~/src/manageiq \
-p durandom \
@spalladino
spalladino / Makefile
Created November 23, 2016 15:40
Proof of concept of Ruby extension written in Crystal
testruby.bundle: testruby.cr
crystal testruby.cr --link-flags "-dynamic -bundle -Wl,-undefined,dynamic_lookup" -o testruby.bundle
irb: testruby.bundle
irb -rtestruby -I.
clean:
rm -rf .crystal testruby.bundle

Kemal vs Sinatra Benchmark

This is just for demonstration purpose. A simple app just returning "Hello World". First in Kemal (Crystal) and then in Sinatra(Ruby with thin).

Kemal (Crystal)

Kemal Version: 0.6.0 Crystal Version: 0.10.0

Crystal vs Node.js Websocket Benchmark

Crystal 0.9.1 with Kemal

require "kemal"

ws "/" do |socket|
  socket.on_message do |message|
 end
$ ruby --version
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-linux]
$ ruby benchmark.rb
user system total real
RedCarpet 0.220000 0.000000 0.220000 ( 0.227063)
kramdown 52.250000 0.000000 52.250000 ( 52.328927)
marked.js 3.660000 0.020000 3.680000 ( 3.632203)
# Machine:
@Fryguy
Fryguy / counts_by_example.patch
Last active November 6, 2015 21:12
Counts of queries in the vmdb specs by example and by file
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 2dff37f..25e5623 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -76,6 +76,25 @@ RSpec.configure do |config|
}
config.include RakeTaskExampleGroup, :type => :rake_task
+ config.before(:suite) do
+ $counts_by_example = {}
@Fryguy
Fryguy / 01 influxdb_metrics.diff
Last active November 6, 2015 21:15
InfluxDB Cap and U metrics
diff --git a/Gemfile b/Gemfile
index 90b36f7..75077b4 100644
--- a/Gemfile
+++ b/Gemfile
@@ -4,6 +4,8 @@ eval_gemfile(File.expand_path("gems/pending/Gemfile", __dir__))
# VMDB specific gems
#
+gem 'influxdb'
+
@codesnik
codesnik / ar_opts.rb
Created September 3, 2015 07:20
using ActiveRecord::PredicateBuilder.register_handler
module AROpts
module Helpers
def GT(val); AROpts::GT.new(val); end
def LT(val); AROpts::LT.new(val); end
def GTE(val); AROpts::GTE.new(val); end
def LTE(val); AROpts::LTE.new(val); end
end
GenericOp = Struct.new(:expression)