Skip to content

Instantly share code, notes, and snippets.

View taqtiqa-mark's full-sized avatar

Mark Van de Vyver taqtiqa-mark

View GitHub Profile
@taqtiqa-mark
taqtiqa-mark / newtype_pattern.rs
Created March 31, 2022 06:23 — forked from nyinyithann/newtype_pattern.rs
The newtype pattern with Deref/DerefMut trait implementation
/*
To implement a trait on a type, the trait or the type has to be local to the code you work on. It is called the orphan rule.
To get around this restriction, we can use the newtype pattern which involves creating a new type in a tuple struct.
Both Vec<T> and Display trait are from the standard library and neither is local to our code.
We are not able to implement Display trait to Vec<T>. But we can construct a wrapper type holding an instance of Vec<T> and implement Display trait on it.
In the following example, VecWrapper<T> struct wraps Vec<T> and implements Display trait.
To get all the methods of Vec<T> available to VecWrapper, Deref trait is implemented on it.
ref: https://doc.rust-lang.org/book/ch19-03-advanced-traits.html?search=borrow%20and%20asref
*/
@taqtiqa-mark
taqtiqa-mark / gist:7d301f7ab6fcef1987dd6b34f8803819
Created January 29, 2020 20:26
droplet discovery over digitalocean private networks

Digital Ocean recently released private networking support in their NYC2 Data center.

They also published a blog post on how to setup a new droplet with private networking. But one thing the post doesn't do is tell you how to scale your private network for many boxes. One approach is obviously to edit /etc/hosts (but this gets annoying when you add a new box). A better way is to create an internal DNS zone (via the digital ocean web interface) and have your droplets use it:

Steps

setup the internal DNS zone file

  1. Login to digital ocean
  2. Click "DNS" on the right hand menu
@taqtiqa-mark
taqtiqa-mark / gist:9bb2f807f2f607bdb2e1402a59370eeb
Created January 29, 2020 20:25 — forked from so0k/gist:cdd24d0a4ad92014a1bc
droplet discovery over digitalocean private networks

Digital Ocean recently released private networking support in their NYC2 Data center.

They also published a blog post on how to setup a new droplet with private networking. But one thing the post doesn't do is tell you how to scale your private network for many boxes. One approach is obviously to edit /etc/hosts (but this gets annoying when you add a new box). A better way is to create an internal DNS zone (via the digital ocean web interface) and have your droplets use it:

Steps

setup the internal DNS zone file

  1. Login to digital ocean
  2. Click "DNS" on the right hand menu
@taqtiqa-mark
taqtiqa-mark / install.sh
Last active December 11, 2015 06:48 — forked from kysnm/install.sh
ubuntu lucid: install tmux 1.7
#!/usr/bin/env bash
export TMUX_INSTALL_VERSION=1.6
wget -q -O - "https://gist.github.com/raw/4561674/install_tmux_${TMUX_INSTALL_VERSION}_on_ubuntu_10.04.sh" | sudo bash
BUNDLE_BIN: .bundle/bin
BUNDLE_SHEBANG: ruby-local-exec
BUNDLE_DISABLE_SHARED_GEMS: '1'
BUNDLE_PATH: vendor
# This is a code example for the Ruby HTTP library Typhoeus
# here's an example for twitter search
# Including Typhoeus adds http methods like get, put, post, and delete.
# What's more interesting though is the stuff to build up what I call
# remote_methods.
class Twitter
include Typhoeus
remote_defaults :on_success => lambda {|response| JSON.parse(response.body)},
:on_failure => lambda {|response| puts "error code: #{response.code}"},
@taqtiqa-mark
taqtiqa-mark / temporary_dsl.rb
Created December 2, 2012 07:48 — forked from sparkertime/temporary_dsl.rb
A Ruby 1.9 DSL strategy
# An unintrusive, temporary DSL strategy.
#
# Why discusses Ruby DSLs and instance_eval vs. block arguments:
# http://hackety.org/2008/10/06/mixingOurWayOutOfInstanceEval.html
#
# This takes advantage of some Ruby 1.9 features to implement a DSL mixin that
# is temporary and doesn't override locally defined methods.
class DslInstance
attr_accessor :script