Skip to content

Instantly share code, notes, and snippets.

View half-ogre's full-sized avatar

Drew Miller half-ogre

View GitHub Profile
#!/bin/bash
# first run 'rails my-app' and 'cd my-app'
git init
touch .gitignore
echo -e "log/*.log\ntmp/**/*\ndoc/api\ndoc/app\ndb/*.sqlite3" >> .gitignore
touch log/.gitignore
touch tmp/.gitignore
touch public/stylesheets/.gitignore
@half-ogre
half-ogre / hash.rb
Created January 9, 2011 19:48
Creating a hash in Ruby with a random salt using /dev/random
require 'base64'
require 'digest/sha2'
def create(text)
salt_bytes = random_salt
salted_hash_bytes = Digest::SHA256.digest(salt_bytes+text)
Base64::encode64(salt_bytes+salted_hash_bytes)
end
def verify(hash, text)
@half-ogre
half-ogre / Get-SaltedHash.ps1
Created January 26, 2011 04:27
I often need to get a hash with a random salt (usually for passwords) for the projects I work on. This is the PS script I use.
function Get-SaltedHash {
param($text)
$csp = new-object System.Security.Cryptography.RNGCryptoServiceProvider
$hashAlgorithm = new-object System.Security.Cryptography.SHA256Managed
$saltBytes = new-object byte[] 8
$csp.GetNonZeroBytes($saltBytes)
$textBytes = [System.Text.Encoding]::UTF8.GetBytes($text)
@half-ogre
half-ogre / CreateUrlHelperToFakeIsLocalUrl
Created July 3, 2011 08:02
It is way too hard to fake a call to Controller.Url.IsLocalUrl, which means I failed as a tester that day.
public static UrlHelper CreateUrlHelperToFakeIsLocalUrl(string fakeRequestUrl)
{
var httpContextBase = new Mock<HttpContextBase>();
httpContextBase.Setup(x => x.Request.Url).Returns(new Uri(fakeRequestUrl));
var requestContext = new RequestContext(httpContextBase.Object, new RouteData());
return new UrlHelper(requestContext);
}
// controller.Url = CreateUrlHelperToFakeIsLocalUrl("http://aFakeHost/aFakePage");
var linksArray = DomUtils.getElementsByTagName("link", item.children, false);
var entryLink = linksArray[0].attribs.href;
for (var i = 0; i < linksArray.length; i++) {
var linkRel = linksArray[i].attribs.rel.toLowerCase();
if (linkRel === 'alternate') {
entryLink = linksArray[i].attribs.href;
break;
}
}
entry.link = entryLink;
@half-ogre
half-ogre / delete_package_registration.sql
Created December 8, 2011 21:27
Deleting a package registration directly in the database
use NuGetGallery
BEGIN TRAN
DECLARE @PackageRegistrationId nvarchar(max)
SET @PackageRegistrationId = '<id>'
ALTER TABLE GallerySettings NOCHECK CONSTRAINT ALL
DELETE FROM PackageStatistics
@half-ogre
half-ogre / gist:1488735
Created December 17, 2011 00:58
A sample Sing-Along event handler
on :say do
nick, text = connection[:nick], data[:text]
raise NickRequiredError if nick.nil?
broadcast :said, { :nick => nick, :text => text }
end
@half-ogre
half-ogre / gist:1766344
Created February 8, 2012 07:12
Pitch for my NoQA talk

NoQA: Context-Driven Testing for Doers

My contention: if you have dedicated testers, you're (probably) doing it wrong. Instead of having separate developers, testers, and project managers, just have one role: doers. I see more and more teams switching to role-less craftsmen; that's good, but I often see these teams struggle when deciding who tests what, and how. My goals for this talk, then, are to first convince you to do away with dedicated testers, and then to prepare you to do so susccessfully (as well as anyone can prepare you for such an undertaking in an hour's time).

@half-ogre
half-ogre / gist:1803665
Created February 11, 2012 19:10
Accessing Node's module cache to build a collection of event processors
// My app uses event sourcing, and I need a collection of all the app's event processors.
// I don't want to maintain this collection by hand, changing every time I add a new processor.
// So, I build up the collection dynamically when the app starts by examining the module cache.
// Caveat: I have no idea whether accessing `require.cache` is supported.
// Note: An event processor is any exported constructor function that ends with 'EventProcessor'.
exports.buildEventProcessorCollection = function() {
var eventProcessors = { };
for (var id in require.cache) {
var mod = require.cache[id];
@half-ogre
half-ogre / gist:1873956
Created February 21, 2012 05:27
Fix for NuGet Gallery #417
var allPackageVersions = packagesQuery.ToList();
var packageVersions = allPackageVersions; ;
if (String.IsNullOrEmpty(version) && !allowPrerelease)
{
// If there's a specific version given, don't bother filtering by prerelease. You could be asking for a prerelease package.
packageVersions = packageVersions.Where(p => !p.IsPrerelease).ToList();
}