Skip to content

Instantly share code, notes, and snippets.

@alanstevens
alanstevens / gist:2764397
Created May 21, 2012 20:17
Script to setup ruby and user accounts on a RPM box
#!/usr/bin/env bash
#
# execute this script with:
# curl https://raw.github.com/gist/2764397/gistfile1.sh | sudo bash
#
function add_user(){
local user_name=$1
local public_key=$2
@alanstevens
alanstevens / Leveling_Up_Abstract.txt
Created September 14, 2012 13:59
Abstract for my talk Leveling Up: When It's Time To Assume Technical Leadership
Leveling Up: When It's Time To Assume Technical Leadership
Most software developers would make lousy managers, but many of the experienced developers that I have met and worked with have more to offer in terms of technical leadership than they share with their managers and team. As an industry, we need you to leverage your experience for the benefit of us all. In this session we will examine some clues that you may be ready to "level up". We'll discuss when and how to appropriately exercise technical leadership and when to keep our mouths shut.
Attendees will leave this session with a toolkit of tactics to influence their teams, companies and clients to make better choices in the pursuit of greater user value.
' This sample from Microsoft does not work on Windows 7 or Server 2008
' Calls to OpenFile and WriteFile fail silently
' The API calls are supposedly supported in Win 7 and Win 8
' Please offer any suggestions in comments
' Obtain a handle to the LPT1 parallel port.
hParallelPort = CreateFile("LPT1", GENERIC_READ Or GENERIC_WRITE, 0, IntPtr.Zero, _
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, IntPtr.Zero)
' Verify that the obtained handle is valid.
@alanstevens
alanstevens / drop_all_tables.sql
Created November 29, 2012 19:16
SQL script to drop all tables in a SQL Server Database
USE [my_database]
GO
/* Drop all non-system stored procs */
DECLARE @name VARCHAR(128)
DECLARE @SQL VARCHAR(254)
SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = 'P' AND category = 0 ORDER BY [name])
WHILE @name is not null
BEGIN
@alanstevens
alanstevens / DependencyResolverStub.cs
Last active December 14, 2015 14:29
ASP.NET MVC IDependencyResolver stub
using System;
using System.Collections.Generic;
using System.Web.Mvc;
using default_auth_review.Controllers;
namespace default_auth_review.Lib
{
public class StubDependencyResolver : IDependencyResolver
{
public object GetService(Type serviceType)
@alanstevens
alanstevens / vagrant_setup.sh
Last active December 15, 2015 17:20
A script to setup a clean Vagrant box for rails development
#!/usr/bin/env bash
#
# execute this script with:
# wget -qO- https://gist.github.com/alanstevens/5296018/raw/vagrant_setup.sh|bash
#
echo "You will be prompted for your password by sudo."
#
@alanstevens
alanstevens / build_signature.rb
Last active December 24, 2015 12:19
Ruby method for building an OAuth 1.0 request signature This validates against http://oauth.googlecode.com/svn/code/javascript/example/signature.html
module OAuth
def self.build_signature oauth
request_params = oauth[:request_params]
request_params[:oauth_consumer_key] = oauth[:oauth_consumer_key]
request_params[:oauth_nonce] = oauth[:oauth_nonce]
request_params[:oauth_signature_method] = 'HMAC-SHA1'
request_params[:oauth_timestamp] = oauth[:oauth_timestamp]
request_params[:oauth_token] = oauth[:oauth_token]
request_params[:oauth_version] = '1.0'
@alanstevens
alanstevens / gist:6813382
Created October 3, 2013 17:11
Ruby encoding is fun!
[29] pry(main)> foo = 'a&b*c d'
=> "a&b*c d"
[30] pry(main)> URI::escape(foo, /[^a-zA-Z0-9\-\.\_\~]/)
=> "a%26b%2Ac%20d"
[31] pry(main)> uri_val = URI.escape(foo, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
=> "a%26b*c%20d"
[32] pry(main)> CGI.escape(foo)
=> "a%26b%2Ac+d"
[33] pry(main)> URI.escape(foo)
=> "a&b*c%20d"
knowledgecenter /knowledgecenter(.:format) {:action=>"knowledgecenter", :to=>#<Proc:0x0000000604c238@/usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.0.10/lib/action_dispatch/routing/mapper.rb:366 (lambda)>}
knowledge_center /knowledge_center(.:format) {:action=>"knowledge_center", :to=>#<Proc:0x0000000602bc18@/usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.0.10/lib/action_dispatch/routing/mapper.rb:366 (lambda)>}
render :update do |page|
page.replace_html 'divCommunityTeamEditor', :partial => '/communities/invite_team_member'
page << "$('#divCommunityTeamMembers').hide();$('#divCommunityTeamEditor').show(); $('#cTeamPW').hide();"
end