Skip to content

Instantly share code, notes, and snippets.

@hoanga
hoanga / myflat.rb
Last active January 25, 2020 04:59
#!/usr/bin/env ruby
# https://gist.github.com/hoanga/4955d1da5479dbff12c3eb33b9d26107
# Returns a flattened version of all elements in the array. Same as Array.flatten
def my_flatten(arr)
result = []
arr.each do |elem|
if elem.kind_of?(Array)
result.concat(my_flatten(elem))
@hoanga
hoanga / Dockerfile
Created March 11, 2018 23:45
Powershell helper functions for kubernetes
FROM kterada0509/docker-revel:latest
EXPOSE 9000
ADD . /go/src/myapp-revel
WORKDIR $GOPATH
CMD revel run myapp-revel
@hoanga
hoanga / gist:1032275
Created June 17, 2011 20:33
Removing server from role
def remove_server_from_role(server, myrole)
save_servers = self.roles[myrole].servers.dup.map { |sss| sss.to_s }
self.roles[myrole].clear
save_servers.each do |serv|
unless serv == server
role myrole, serv
end
end
#!/bin/bash
SYSTEMS=$(sudo cobbler system list)
DOMAIN_NAME=$(cat /etc/resolv.conf | grep -E '^search' | awk ' { print $2 } ')
for sys in $SYSTEMS
do
IPADDRS=$(sudo cobbler system report --name=$sys | grep 'IP Address' | awk ' { print $4 } ' | sort | uniq)
ENTRIES="$IPADDRS $sys $sys.$DOMAIN_NAME"
require 'rubygems'
require 'gdata'
require 'sinatra'
def is_gapp_user?(user, password)
client = GData::Client::GMail.new
begin
token = client.clientlogin(user, password)
return token
rescue GData::Client::AuthorizationError
#!/usr/local/bin/node
// Program Name: watchfile.js
// Purpose: Monitor a set of files given on the command-line
// Usage: ./watchfile.js /tmp/foo /tmp/bar
// Output: 2009-11-25T04:50:44Z|/tmp/foo
var sys = require('sys');
process.ARGV.forEach(function (f) {
#!/bin/sh
RUBY19_URL="ftp://ftp.ruby-lang.org/pub/ruby/1.9"
RUBY19_VERS="ruby-1.9.1-p243"
echo "============================="
echo "Downloading and extracting..."
echo "============================="
cd ~/Downloads && wget -c "${RUBY19_URL}/${RUBY19_VERS}.tar.gz"
#!/usr/bin/env ruby
require 'net/imap'
require 'rubygems'
require 'tmail'
# Introduction:
#
# This small library is to archive emails from an imap server
#!/bin/sh
# Program Name: setup-zone-exclusive.sh
# Author: Alain Hoang
# Purpose: Wrapper around setting up an ipkg branded zone with
# an exclusive interface
# Notes: If you want DHCP you will need the script from the following URL
# http://www.linuxtopia.org/online_books/opensolaris_2008/SYSADV3/html/extkj.html
# Copy that to dhcp-client-event.sh
#
# Copyright (c) 2009, Alain Hoang
@hoanga
hoanga / deploy-gateway-non-standard-port.rb
Created May 21, 2009 00:37
Snippet for setting a Capistrano SSH gateway to a non-standard port
# Capistrano snippet
# Set the SSH gateway to a non standard port (22000)
set :gateway, 'mysshgateway.com:22000'