Skip to content

Instantly share code, notes, and snippets.

View alenia's full-sized avatar

alenia

View GitHub Profile
@alenia
alenia / eulerMethods.js
Created July 22, 2011 02:19
Why is this so much slower in Ruby than in Node?
exports.divisors_count = function (n) {
var count = 0
var bound = Math.floor(Math.sqrt(n))
if (bound*bound == n) {
count = 1;
bound -= 1;
}
else if ((bound+1)*(bound+1) == n) {
count = 1;
}
@alenia
alenia / gist:1643793
Created January 19, 2012 23:45
Roadie stack trace
-- control frame ----------
c:0103 p:---- s:0452 b:0452 l:000451 d:000451 CFUNC :respond_to?
c:0102 p:0013 s:0448 b:0448 l:000447 d:000447 METHOD .../gems/activesupport-3.1.3/lib/active_support/core_ext/class/inheritable_attr
c:0101 p:---- s:0443 b:0443 l:000442 d:000442 FINISH
c:0100 p:0011 s:0441 b:0441 l:000440 d:000440 CLASS .../gems/mail-2.3.0/lib/mail/elements/content_type_element.rb:3
c:0099 p:0009 s:0439 b:0439 l:000438 d:000438 TOP .../gems/mail-2.3.0/lib/mail/elements/content_type_element.rb:2
c:0098 p:---- s:0437 b:0437 l:000436 d:000436 FINISH
c:0097 p:0027 s:0435 b:0435 l:000434 d:000434 METHOD .../gems/mail-2.3.0/lib/mail/fields/content_type_field.rb:37
c:0096 p:0055 s:0432 b:0432 l:000431 d:000431 METHOD .../gems/mail-2.3.0/lib/mail/fields/content_type_field.rb:31
c:0095 p:0165 s:0428 b:0428 l:000427 d:000427 METHOD .../gems/mail-2.3.0/lib/mail/fields/content_type_field.rb:23
@alenia
alenia / gist:4945954
Created February 13, 2013 16:43
A spec level overview of rspec_mocks and rspec_spies syntax
# When using the gems rspec_mocks and rspec_spies
class Widget
def a_method
'I am a method!'
end
end
describe Widget do
let(:item) {Widget.new}
@alenia
alenia / gist:5080383
Last active December 14, 2015 11:39
Two ways of making cylinders in SASS for webkit
@mixin cylinder($width,$height,$proportion: .4)
position: relative
width: $width
height: $height
&:before, &:after
// only using chrome for now, so not adding in moz
-webkit-transform: scaley($proportion)
width: $width
height: $width
border-radius: $width
@alenia
alenia / gist:6273654
Last active December 21, 2015 07:48
Add deep_diff method to Hash to more easily see locations of differences between crazy nested hashes.
class DiffObject
attr :left, :right
def initialize(left, right)
@left = left
@right = right
end
end
class Hash
# a_hash.deep_diff(b_hash) returns:
@alenia
alenia / components.js
Created May 23, 2017 17:13
types of components
// fails linter
myComponent1 = ({tintColor}) => <Image style={{tintColor}} />
// passes linter
myComponent2 = ({tintColor}) => <Image style={{tintColor}} />
myComponent2.propTypes = {
tintColor: PropTypes.string.isRequired
}
// fails linter
const mockRootNavigator1 = function() {
return {
router: {
getComponentForState: jest.fn
}
}
}
function mockRootNavigator2() {
return {