Skip to content

Instantly share code, notes, and snippets.

@scrogson
scrogson / palindrome.rb
Created March 30, 2009 08:39
Add a palidrome? method to the Ruby String ojbect. Completely pointless.
class String
def palindrome?
self.gsub!(/[[:punct:][:space:]]/, '')
self.downcase == self.downcase.reverse
end
end
@scrogson
scrogson / prob.php
Created April 20, 2009 15:22
(PHP)
<?php
function benford($str) {
$nums = explode(' ', $str);
$nums = array_map('firstChar', $nums);
$total = sizeof($nums);
$histogram = array();
foreach ($nums as $num) {
if (isset($histogram[$num])) {
@scrogson
scrogson / letter_stats.rb
Created April 27, 2009 08:08
Letter histogram
def letter_stats(string)
string.gsub!(/[^A-z]/, '').upcase!
letters = {}
string.split('').each do |letter|
if letters[letter].nil?
letters[letter] = { sightings: 1,
frequency: (1.to_f / string.size.to_f * 100).ceil }
else
letters[letter][:sightings] += 1
letters[letter][:frequency] = (letters[letter][:sightings].to_f / string.size.to_f * 100).ceil
@scrogson
scrogson / README.md
Last active November 14, 2017 13:06
Shell functions to aid in using hub(1) with GitHub Enterprise.

I recently started working at Blue Box and we use GitHub Enterprise (GHE) for all of our apps. I had gotten in the habit of using hub to improve my git workflow and was curious if I could use hub with GHE. I turned to the docs and sure enough, you can!

The docs tell you two ways of setting up hub to use GHE:

By default, hub will only work with repositories that have remotes which point to github.com. GitHub Enterprise hosts need to be whitelisted to configure hub to treat such remotes same as github.com:

$ git config --global --add hub.host my.git.org
@scrogson
scrogson / git-tips.md
Created March 21, 2013 04:56
Collection of Git Tips

Deleted files on disk but wanted to remove them from git?

$ git rm $(git ls-files --deleted)

Need to undelete files you accidentally deleted?

$ git co -- $(git ls-files --deleted)
check_member_option(Host, Element, Option) ->
%% Won't this always evaluate to true?
true = case try_get_option(Host, Option, all) of
all -> true;
AllowedValues -> lists:member(Element, AllowedValues)
end;
$ iex -S mix (2.1.0)
Erlang R16B03-1 (erts-5.10.4) [source] [smp:8:8] [async-threads:10] [kernel-poll:false]
Unchecked dependencies for environment dev:
* wsock (git://github.com/madtrick/wsock.git)
the dependency wsock in deps/escalus/rebar.config is overriding a child dependency:
> In deps/escalus/rebar.config:
{:wsock, ~r".*", [git: "git://github.com/madtrick/wsock.git", tag: "1.1.3"]}
source 'https://rubygems.org'
group :development do
gem 'knife-solo_data_bag'
gem 'berkshelf', github: 'berkshelf/berkshelf'
end
group :plugins do
gem 'vagrant-berkshelf', github: 'berkshelf/vagrant-berkshelf'
gem 'vagrant-omnibus', github: 'schisamo/vagrant-omnibus'
@scrogson
scrogson / config-initializers-sandbox_email_interceptor.rb
Last active August 29, 2015 14:00
Intercept outgoing email in environments outside of production.
# config/initializers/sandbox_email_interceptor.rb
ActionMailer::Base.register_interceptor(SandboxEmailInterceptor) unless Rails.env.production?
find_by_room_and_user(Room, User) ->
qlc:q([X || X <- mnesia:table(muc_joins),
X#muc_joins.room =:= Room,
X#muc_joins.user =:= User]).