Skip to content

Instantly share code, notes, and snippets.

View zenchild's full-sized avatar

Dan Wanek zenchild

View GitHub Profile
@zenchild
zenchild / playing_with_gc.rb
Last active August 29, 2015 14:08
Playing with the Ruby Garbage Collector
require "objspace"
class TestWithFinalizer
def self.finalizer
proc {|o_id| puts "Collected #{o_id}"}
end
def test
3.times.each_with_object(mark []) {|i,a|
@zenchild
zenchild / ViewpointArchitecture.md
Last active December 25, 2015 09:29
An overview of the Viewpoint code architecture.

Viewpoint Code Architecture

Viewpoint Overview

Viewpoint is built with two major components in its overall architecture. There is the back-end, which talks via SOAP messages to the Exchange Web Services (EWS) endpoint and the front-end which provides an easier-to-use interface and is intended as the main point of user interaction. The front-end was not intended to fulfill all of the capabilities that EWS provides but give users and path with little resistance to get most tasks done. Should someone need to reach into the depths of the more obscure the back-end could be tapped to help out with those instances.

Code History

@zenchild
zenchild / custom_validation.rb
Created September 4, 2013 15:43
Extend ActiveRecord with the ability to have instance-level validations.
# Dan Wanek <[email protected]>
# 2013-09-04T15:41:31+00:0
#
# This extension can be used to create instance-level validations. For example
# if you have an instance of 'user' you can do something like the following:
# @example:
# user.custom_validation ->(scope) {
# if scope.bad_logins >= account.max_bad_logins
# scope.errors.add :bad_logins, "too many bad logins for your account policy"
# end
@zenchild
zenchild / gap_algorithms_test.rb
Created October 26, 2012 21:19
Adaptive Time Clustering Algorithm
require 'time'
class GapMean
THE_ANSWER_TO_LIFE_AND_EVERYTHING = 42
K = Math.log(THE_ANSWER_TO_LIFE_AND_EVERYTHING)
attr_reader :gaps, :running_total, :exp, :window
def initialize(seq)
@seq = seq
@zenchild
zenchild / message_pass.txt
Created June 7, 2012 14:28
Message Passing Benchmarks
# Go
rate: 3391320.62
rate: 3393174.22
rate: 3381328.82
# C
Rate: 4409458.639422 (count: 50000000)
Rate: 3165676.958497 (count: 50000000)
Rate: 4281366.171821 (count: 50000000)
@zenchild
zenchild / build64.sh
Created April 26, 2012 00:54
A Linux preloader to preempt logins for apps with 8 char dependencies
gcc -fPIC -rdynamic -g -c -Wall getpwuid_preload64.c
gcc -fPIC -rdynamic -g -c -Wall getlogin_preload64.c
gcc -shared -WI,-soname,libcpreload64.so.1 -o libcpreload64.so.1.0.1 getpwuid_preload64.o getlogin_preload64.o -lc -ldl
@zenchild
zenchild / hi.vim
Created March 29, 2012 15:51
Highlight the word under the cursor.
:nnoremap <silent> <leader>h1 :hi W1 guibg=#aeee00 guifg=#000000 ctermbg=154 ctermfg=16<cr> :execute 'match W1 /\<<c-r><c-w>\>/'<cr>
@zenchild
zenchild / file_lastline.rb
Created February 14, 2012 01:25
Return the last line of a File in a O(n) time
class File
def last_line
ind = 1
loop do
offset = (ind * -80)
if(offset >= size)
seek(0, IO::SEEK_SET)
line = read
line.chomp!
return line.split(/\n/, -1).last
@zenchild
zenchild / nokogiri_build.rb
Created January 13, 2012 13:37
Nokogiri parameterized Builder
require 'nokogiri'
def mkxml(b, nm, bhash)
b.send(nm.to_s) {
bhash.each_pair do |k, v|
if(v.is_a?(Hash))
mkxml(b, k, v)
elsif(v.is_a?(Array))
b.send(k, v.shift, v[0].keys.first => v[0].values.first)
else
@zenchild
zenchild / ldap_user_rpt.ps1
Created August 25, 2011 03:55
Create an Excel report of Active Directory Users in an OU
# A script to fetch AD Users and put them into a spreadsheet
# Dan Wanek <[email protected]>
# 08/24/2011 22:36:00
param(
[int]$limit = 20,
[string]$ou = "",
[string]$outFile = $(Get-Location).Path + "\LDAP_USER_RPT.xls",
[switch]$verbose,
[switch]$usage