Skip to content

Instantly share code, notes, and snippets.

View bartolsthoorn's full-sized avatar

Bart Olsthoorn bartolsthoorn

View GitHub Profile
@bartolsthoorn
bartolsthoorn / kepler.coffee
Last active December 31, 2015 01:19
Keplerian rates to coordinates
# Based on NASA JPL - http://ssd.jpl.nasa.gov/txt/aprx_pos_planets.pdf
# Perhaps increase accuracy with big.js
keplerian_position = (data, centuries) ->
data = data.kepler
T = centuries # past J2000.0
# http://ssd.jpl.nasa.gov/txt/p_elem_t1.txt
keplerian_value = (data, value, T) ->
data[value + '0'] + data[value + '1'] * T
# Based on NASA JPL - http://ssd.jpl.nasa.gov/txt/aprx_pos_planets.pdf
# Perhaps increase accuracy with big.js
keplerian_position = (data, centuries) ->
T = centuries # past J2000.0
# http://ssd.jpl.nasa.gov/txt/p_elem_t1.txt
keplerian_value = (data, value, T) ->
data[value + '0'] + data[value + '1'] * T
*******************************************************************************
Ephemeris / WWW_USER Fri Oct 25 12:57:27 2013 Pasadena, USA / Horizons
*******************************************************************************
Target body name: Earth (399) {source: DE-0431LE-0431}
Center body name: Sun (10) {source: DE-0431LE-0431}
Center-site name: BODY CENTER
*******************************************************************************
Start time : A.D. 2013-Oct-21 00:00:00.0000 CT
Stop time : A.D. 2013-Nov-20 00:00:00.0000 CT
Step-size : 1440 minutes

Install Cucumber with Rspec, Guard and Spork

Using during Hartl rails 4.0 guide (http://ruby.railstutorial.org/chapters)

Gems

group :development, :test
  gem 'guard-rspec'
  gem 'guard-livereload'
  gem 'spork-rails', github: 'sporkrb/spork-rails' # rubygems version not rails 4 compatible
  gem 'guard-spork'
@bartolsthoorn
bartolsthoorn / compare_state_errors.c
Last active December 19, 2015 09:09
Hopfield networks; checks errors in current state vs patterns
static VALUE hopfield_calculate_state_errors(VALUE self, VALUE state, VALUE patterns) {
// Compare state to patterns and calculate errors for each pattern
int patterns_count = (int) RARRAY_LEN(patterns);
int pattern_length = (int) RARRAY_LEN(state);
VALUE errors = rb_ary_new2(patterns_count);
for(int p = 0; p < patterns_count; p++) {
int sum = 0;
@bartolsthoorn
bartolsthoorn / spec_helper.rb
Created June 2, 2013 22:57
To enable RSpec when you are using a C extension in a gem, just add something like this to your spec helper. It will build the C code every time you run `rspec`
# Include C extension
puts 'Building C extension'
Dir.chdir('ext/hola') do
output = `ruby extconf.rb`
raise output unless $? == 0
output = `make`
raise output unless $? == 0
end
@bartolsthoorn
bartolsthoorn / blabla.rb
Created May 3, 2013 15:22
Addressable parsing domain.com - wrong
uri = Addressable::URI.parse('http://www.google.com -')
uri.host
# => "www.google.com -"
# Trying Domainatrix
d = Domainatrix.parse(uri.host)
#<Domainatrix::Url:0x007febb38c41e0
@domain="google",
@host="www.google.com -",
@path="",
@bartolsthoorn
bartolsthoorn / wombat_is_cool.rb
Created March 14, 2013 12:43
Wombat is pretty cool
results = Wombat.crawl do
base_url "#{uri.scheme}://#{uri.host}"
path uri.path
title xpath: '//title'
meta do
description xpath: '//meta[@name="description"]/@content'
keywords xpath: '//meta[@name="keywords"]/@content'
end
mailto "xpath=//a[starts-with(@href, 'mailto')]", :list
end
@bartolsthoorn
bartolsthoorn / ContainerViewController.mm
Created March 9, 2013 19:27
openMainMenu works properly and animates the view in, closeMainMenu does not animate..
- (void)openMainMenu {
_menu_opened = YES;
_darknessOverlay.hidden = NO;
CGRect oldFrame = _menuView.frame;
CGRect f = _menuView.frame;
f.origin.x = _menuView.frame.size.width * -1;
_menuView.frame = f;
CGRect newFrame = CGRectMake(_menuView.frame.size.width*-1, _menuView.frame.origin.y, _menuView.frame.size.width, _menuView.frame.size.height);
_menuView.frame = CGRectMake(0, _menuView.frame.origin.y, _menuView.frame.size.width, _menuView.frame.size.height);
[UIView animateWithDuration:0.5
animations:^{
_menuView.frame = newFrame;
}];