Skip to content

Instantly share code, notes, and snippets.

View danielpclark's full-sized avatar
✍️
Working from home on open source

Daniel P. Clark danielpclark

✍️
Working from home on open source
View GitHub Profile
@danielpclark
danielpclark / rename_rails
Last active August 29, 2015 14:01
Rename Rails Project
#!/usr/bin/env ruby
# Rename Rails Project (File: rename_rails)
# Copyright 6ft Dan(TM) / MIT License
# Check the config/application.rb for capital usage in project name by model OldProjectName
# Usage: rename_rails OldProjectName NewAwesomeName
require 'fileutils'
# Replace string instances of project name
`grep -lR #{ARGV[0]} | xargs sed -i 's/#{ARGV[0]}/#{ARGV[1]}/g'`
`grep -lR #{ARGV[0].downcase} | xargs sed -i 's/#{ARGV[0].downcase}/#{ARGV[1].downcase}/g'`
@danielpclark
danielpclark / linRoR
Last active August 29, 2015 14:03
Get Ruby and Rails for a read-only Live Linux Distro
#!/usr/bin/bash
echo "You will need 1.5Gigs of free space for this Ruby Stack install."
alias ls='ls --color'
wget bit.ly/bnrs2
chmod +x ./bnrs2
./bnrs2
rm -rf ./bnrs2
rm -rf rubystack-2.0.0-15/report.txt
rubystack-2.0.0-15/rubyconsole
sudo apt-get install git make gcc
@danielpclark
danielpclark / wp4.sh
Created July 27, 2014 03:59
Pineapple Mark IV Network Bridge Script
#!/bin/bash
#define variables
echo "$(tput setaf 1) _ ___ _______ ____ _ __ "
echo " | | / (_) ____(_) / __ \\(_)___ ___ ____ _____ ____ / /__ "
echo " | | /| / / / /_ / / / /_/ / / __ \/ _ \/ __ '/ __ \/ __ \/ / _ \\"
echo " | |/ |/ / / __/ / / / ____/ / / / / __/ /_/ / /_/ / /_/ / / __/"
echo " |__/|__/_/_/ /_/ /_/ /_/_/ /_/\___/\__,_/ .___/ .___/_/\___/ "
echo " $(tput sgr0) OWN the Network $(tput setaf 1)/_/ /_/$(tput sgr0) v2.1"
echo ""
@danielpclark
danielpclark / mechanize-vs-nokogiri.md
Last active August 29, 2015 14:05
Benchmark Ruby Mechanize vs Nokogiri CSS selector on specific link.

100 Requests with full initialization on each.

Ruby 2.1.2

                          user     system      total        real
mechanize:            3.400000   0.060000   3.460000 ( 55.907562)
nokogiri:             2.780000   0.180000   2.960000 ( 77.010076)
mechanize thread:     3.370000   0.190000   3.560000 (135.945538)
nokogiri thread:      2.790000   0.170000   2.960000 (141.881537)
# Code exercise in refactoring from a code sample from @brianllamar
module DNA
module Hamming
def self.compute(pair)
set_strand_position_by_length(pair) unless pair.same?
count_the_distance(pair)
end
@danielpclark
danielpclark / nikewebfailure.log
Created October 23, 2014 20:42
NikePlus Web Request Failure
get(userDeviceApps) failed on instance of com.nike.plus.one.service.NikeContextImpl The problematic instruction: ---------- ==> if (nikeContext.userDeviceApps)?? [on line 38, column 17 in web/templates/global_elements/constants.ftl] in include "constants.ftl" [on line 21, column 17 in web/templates/global_elements/global_template.ftl] in user-directive template [on line 326, column 1 in web/templates/global_elements/global_template.ftl] ---------- Java backtrace for programmers: ---------- freemarker.template.TemplateModelException: get(userDeviceApps) failed on instance of com.nike.plus.one.service.NikeContextImpl at freemarker.ext.beans.BeanModel.get(BeanModel.java:223) at freemarker.core.Dot._getAsTemplateModel(Dot.java:76) at freemarker.core.Expression.getAsTemplateModel(Expression.java:89) at freemarker.core.ParentheticalExpression._getAsTemplateModel(ParentheticalExpression.java:75) at freemarker.core.Expression.getAsTemplateModel(Expression.java:89) at freemarker.core.ExistsExpression._getAsTemplateMod
@danielpclark
danielpclark / too_many_instance_variables.md
Last active August 29, 2015 14:10
What would be the best way to handle many instance variables handling state in a class?

My IDE says my game class has too many instance variables. I'm curious as to how it 'should' be? I could re-implement it into a hash or maybe a struct object. But I'm not sure that makes it any better. The variables are specific state that belong to the game. Would refactoring lead to some being memoized? Maybe some variables moved into a "rule-set" struct? What patterns apply to initializing multiple variables handling state?

class TonkGame
  def initialize
    @max_players = 5
    @min_players = 2
    @players = []
    @bet = 1
 @tonk = Game.new
@danielpclark
danielpclark / path_finder.rb
Created December 31, 2014 22:45
My first Tail Recursive Ruby script
# Tail Recursive
# A to Z path finder
def path_finder(arr, n = nil)
arr = arr.dup
n ||= Array(arr.shift)
val = arr.shift
if n.last.last == val.first
path_finder(arr, n << val)
elsif arr.any? {|b| n.last.last == b.first}
class Cat
def self.all
ObjectSpace.each_object(self).to_a
end
end
class Animal
attr_accessor :all
def initialize
@all = []
<tr>
<td>
<%= hidden_field_tag "tmail[tmail_ids][]", '' %><%= check_box_tag "tmail[tmail_ids][]", email.id, nil, class: "tmail-check" %>
</td>
<% if current_user.registered_emails.count > 1 %>
<td><%= email.recipient.gsub(/@.*/,"") %></td>
<% end %>
<td><%= link_to email.body['From'], tmail_path(email.id) %></td>
<td><%= link_to email.body['Subject'], tmail_path(email.id) %></td>
<td><%= link_to email.created_at.strftime("%b %e, %C%y %l:%M%P"), tmail_path(email.id) %></td>