bad_ass_extensions 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.mdown +126 -0
- data/VERSION +1 -1
- data/bad_ass_extensions.gemspec +70 -0
- data/lib/bad_ass_extensions/cookie_debugger.rb +15 -0
- data/lib/bad_ass_extensions/hash.rb +1 -1
- metadata +7 -5
- data/README.rdoc +0 -23
data/README.mdown
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
# bad\_ass\_extensions
|
2
|
+
|
3
|
+
Bad Ass Extensions are a set of standard library extensions and tools I use on a regular basis.
|
4
|
+
|
5
|
+
## Installing
|
6
|
+
|
7
|
+
gem install bad_ass_extensions
|
8
|
+
|
9
|
+
## Docs
|
10
|
+
|
11
|
+
|
12
|
+
### Array
|
13
|
+
|
14
|
+
#### sort\_by\_list
|
15
|
+
A way of sorting a list by using a predetermined sort order of an attribute. For instance, if you had a list of User objects, you can sort them by passing in a list of ordered attributes, such as
|
16
|
+
|
17
|
+
User.all.sort_by_list(["Boss", "Manager", "Worker", "Janitor"])
|
18
|
+
|
19
|
+
|
20
|
+
#### frequency_list
|
21
|
+
Takes an array of items and returns a list new array of how frequent those items are, for example:
|
22
|
+
|
23
|
+
> [1, 1, 3, 3, 4, 4, 4, 5].frequency_list
|
24
|
+
|
25
|
+
## OUTPUT
|
26
|
+
## [[1, 2], [3,2], [4,3], [5,1]]
|
27
|
+
|
28
|
+
#### uniquify
|
29
|
+
Takes an array of items and returns a new list of of items based upon a block you pass in, for example:
|
30
|
+
|
31
|
+
> people << Person.new(:first_name => "Jason", :career => "Superman")
|
32
|
+
> people << Person.new(:first_name => "Mike", :career => "Engineer")
|
33
|
+
> people << Person.new(:first_name => "Aaron", :career => "Dog Walker")
|
34
|
+
> people << Person.new(:first_name => "Joseph", :career => "Dog Walker")
|
35
|
+
> people << Person.new(:first_name => "Allen", :career => "Superman")
|
36
|
+
> people.uniquify{|p| p.career}
|
37
|
+
|
38
|
+
## OUTPUT
|
39
|
+
## ["Jason", "Mike", "Aaron"] ## would return the Person object really
|
40
|
+
|
41
|
+
### Enumerable
|
42
|
+
|
43
|
+
#### group_count
|
44
|
+
Probably my favorite of all... You can take an array of items and it groups them by whatever block you pass in, and then returns a hash where the keys are what you were grouping on, and the value is the count of items in the group.
|
45
|
+
|
46
|
+
> ['beholder', 'medusa', 'medusa', 'dog', 'dog', 'cat', 'person', 'dingo', 'bear', 'nharwal', 'nharwal', 'cyclops', 'dog'].group_count{|being| being }
|
47
|
+
|
48
|
+
## OUTPUT
|
49
|
+
## {"cat"=>1, "person"=>1, "medusa"=>2, "nharwal"=>2, "beholder"=>1, "dog"=>3, "bear"=>1, "dingo"=>1, "cyclops"=>1}
|
50
|
+
|
51
|
+
### Hash
|
52
|
+
|
53
|
+
#### rowized
|
54
|
+
Just a clean way of displaying hash data
|
55
|
+
|
56
|
+
> hash = {"cat"=>1, "person"=>1, "medusa"=>2, "nharwal"=>2, "beholder"=>1, "dog"=>3, "bear"=>1, "dingo"=>1, "cyclops"=>1}
|
57
|
+
> puts hash.rowized
|
58
|
+
|
59
|
+
## OUTPUT
|
60
|
+
cat: 1
|
61
|
+
person: 1
|
62
|
+
nharwal: 2
|
63
|
+
medusa: 2
|
64
|
+
beholder: 1
|
65
|
+
dog: 3
|
66
|
+
bear: 1
|
67
|
+
cyclops: 1
|
68
|
+
dingo: 1
|
69
|
+
|
70
|
+
### Date
|
71
|
+
Just added the ability to find differences between 2 dates
|
72
|
+
|
73
|
+
#### days_between(start, finish)
|
74
|
+
|
75
|
+
#### weeks_between(start, finish)
|
76
|
+
|
77
|
+
#### months_between(start, finish)
|
78
|
+
|
79
|
+
#### years_between(start, finish)
|
80
|
+
|
81
|
+
FROM: http://rails.lighthouseapp.com/projects/8994/tickets/879-finding-the-days-weeks-months-years-between-two-dates
|
82
|
+
|
83
|
+
### Histogram
|
84
|
+
|
85
|
+
Often I need to see how the data patterns are going from one day to the next... How many emails were sent out between 1 & 2pm, or How many orders were done by hour this day. I find that looking at histograms really allows you to see how things are behaving and gives great insight into your data.
|
86
|
+
|
87
|
+
This histogram class is just my simple attempt at getting data from a variety of different data structures (needs to be in some decent original form).
|
88
|
+
|
89
|
+
From the sample output, you can see that on the last day, there was some spike in activity during the early afternoon (Hours 13 and 14).
|
90
|
+
|
91
|
+
Just a useful tool in your arsenal of data mining.
|
92
|
+
|
93
|
+
Checkout: http://forrst.com/posts/Histogram\_for\_Command\_Line\_IRB\_usage-1Zn for a display of usage
|
94
|
+
|
95
|
+
### RailsCookieDebugger
|
96
|
+
|
97
|
+
require 'rubygems'
|
98
|
+
require 'bad_ass_extensions'
|
99
|
+
cookie = "BAh7ByIQX2NzcmZfdG9rZW4iMWRDejZSMEw2cXcyMTBaWVhzRnZGSU92SFFGUHM1R2VrZUNTeHR4ODd5aUk9Ig9zZXNzaW9uX2lkIiU4ZWRlN2UwYWQ3NDhhMjVmNDUzNTYyYTRiY2MzMDc3Yw%3D%3D--05f7a04ebbe9fec2f70d8ad9faaddfedd7863912"
|
100
|
+
session = RailsCookieDebugger.show_session(cookie)
|
101
|
+
pp session
|
102
|
+
|
103
|
+
# Output
|
104
|
+
{"_csrf_token"=>"dCz6R0L6qw210ZYXsFvFIOvHQFPs5GekeCSxtx87yiI=",
|
105
|
+
"session_id"=>"8ede7e0ad748a25f453562a4bcc3077c"}
|
106
|
+
|
107
|
+
|
108
|
+
## Contributing to bad\_ass\_extensions
|
109
|
+
|
110
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
111
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
112
|
+
* Fork the project
|
113
|
+
* Start a feature/bugfix branch
|
114
|
+
* Commit and push until you are happy with your contribution
|
115
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
116
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
117
|
+
|
118
|
+
## TODO
|
119
|
+
|
120
|
+
needs some serious testing
|
121
|
+
|
122
|
+
## Copyright
|
123
|
+
|
124
|
+
Copyright (c) 2011 Jason Amster. See LICENSE.txt for
|
125
|
+
further details.
|
126
|
+
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{bad_ass_extensions}
|
8
|
+
s.version = "0.2.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Jason Amster"]
|
12
|
+
s.date = %q{2011-01-21}
|
13
|
+
s.description = %q{Some bad ass extensions I use all the time}
|
14
|
+
s.email = %q{jayamster@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.mdown"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"Gemfile",
|
22
|
+
"LICENSE.txt",
|
23
|
+
"README.mdown",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"bad_ass_extensions.gemspec",
|
27
|
+
"lib/bad_ass_extensions.rb",
|
28
|
+
"lib/bad_ass_extensions/array.rb",
|
29
|
+
"lib/bad_ass_extensions/cookie_debugger.rb",
|
30
|
+
"lib/bad_ass_extensions/date.rb",
|
31
|
+
"lib/bad_ass_extensions/enumerable.rb",
|
32
|
+
"lib/bad_ass_extensions/hash.rb",
|
33
|
+
"lib/bad_ass_extensions/histogram.rb",
|
34
|
+
"lib/bad_ass_extensions/object.rb",
|
35
|
+
"test/helper.rb",
|
36
|
+
"test/test_bad_ass_extensions.rb"
|
37
|
+
]
|
38
|
+
s.homepage = %q{http://github.com/jamster/bad_ass_extensions}
|
39
|
+
s.licenses = ["MIT"]
|
40
|
+
s.require_paths = ["lib"]
|
41
|
+
s.rubygems_version = %q{1.3.7}
|
42
|
+
s.summary = %q{Some bad ass extensions I use all the time}
|
43
|
+
s.test_files = [
|
44
|
+
"test/helper.rb",
|
45
|
+
"test/test_bad_ass_extensions.rb"
|
46
|
+
]
|
47
|
+
|
48
|
+
if s.respond_to? :specification_version then
|
49
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
50
|
+
s.specification_version = 3
|
51
|
+
|
52
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
53
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
54
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
55
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
56
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
57
|
+
else
|
58
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
59
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
60
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
61
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
62
|
+
end
|
63
|
+
else
|
64
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
65
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
66
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
67
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'base64'
|
3
|
+
require 'CGI'
|
4
|
+
require 'pp'
|
5
|
+
|
6
|
+
class RailsCookieDebugger
|
7
|
+
class << self
|
8
|
+
def show_session(cookie)
|
9
|
+
Marshal.load(Base64.decode64(CGI.unescape(cookie.split("\n").join).split('--').first))
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bad_ass_extensions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jason Amster
|
@@ -86,16 +86,18 @@ extensions: []
|
|
86
86
|
|
87
87
|
extra_rdoc_files:
|
88
88
|
- LICENSE.txt
|
89
|
-
- README.
|
89
|
+
- README.mdown
|
90
90
|
files:
|
91
91
|
- .document
|
92
92
|
- Gemfile
|
93
93
|
- LICENSE.txt
|
94
|
-
- README.
|
94
|
+
- README.mdown
|
95
95
|
- Rakefile
|
96
96
|
- VERSION
|
97
|
+
- bad_ass_extensions.gemspec
|
97
98
|
- lib/bad_ass_extensions.rb
|
98
99
|
- lib/bad_ass_extensions/array.rb
|
100
|
+
- lib/bad_ass_extensions/cookie_debugger.rb
|
99
101
|
- lib/bad_ass_extensions/date.rb
|
100
102
|
- lib/bad_ass_extensions/enumerable.rb
|
101
103
|
- lib/bad_ass_extensions/hash.rb
|
data/README.rdoc
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
= bad_ass_extensions
|
2
|
-
|
3
|
-
Bad Ass Extensions are a set of standard library extensions and tools I use on a regular basis.
|
4
|
-
|
5
|
-
== Contributing to bad_ass_extensions
|
6
|
-
|
7
|
-
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
|
-
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
|
-
* Fork the project
|
10
|
-
* Start a feature/bugfix branch
|
11
|
-
* Commit and push until you are happy with your contribution
|
12
|
-
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
-
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
-
|
15
|
-
== TODO
|
16
|
-
|
17
|
-
needs some serious testing
|
18
|
-
|
19
|
-
== Copyright
|
20
|
-
|
21
|
-
Copyright (c) 2011 Jason Amster. See LICENSE.txt for
|
22
|
-
further details.
|
23
|
-
|