Skip to content

Instantly share code, notes, and snippets.

@Sujimichi
Sujimichi / Gemfile
Created August 11, 2017 14:48
Gemfile info for stackoverflow question
source 'http://rubygems.org'
ruby "2.2.5"
gem 'rails', '3.2.22'
gem 'pg', '0.17.0'
gem 'puma'
gem 'platform-api'
@Sujimichi
Sujimichi / ToolBarTest.cs
Created October 5, 2016 16:12
KSP toolbar setup not working as expected
using System;
using UnityEngine;
using KSP.UI.Screens;
namespace ToolBarTest
{
[KSPAddon(KSPAddon.Startup.MainMenu, false)]
public class ToolBarTest : MonoBehaviour
{
@Sujimichi
Sujimichi / db.rake
Created January 29, 2016 19:20
A (slightly offensive) set of rake tasks for backing up, listing backups and restoring backups for a pg rails app (with checks to ensure server and console aren't running before performing restore)
namespace :db do
task :backup => :environment do
db = ActiveRecord::Base.connection_config[:database]
file = Rails.root.join("db", "backups", "#{Time.now.strftime("%Y%m%d%H%M%S")}_#{db}.psql")
puts "Preparing to back yo shit up....\ngimme dat password fool:"
system "pg_dump -F c -v -h localhost -d #{db} -f #{file}"
puts "\nI done stuffed your worthless data in #{file}\n"
end
@Sujimichi
Sujimichi / genome_epic
Created May 27, 2012 02:15
Reduced Version of my NN solution to RubyWarrior. Without support for using different layered NN's and extra comments removed. Includes two evolved genomes, put one in a file called 'genome' with player.rb in warrior folder
0.4208665093792384,0.8271085823481578,-0.08677969236421801,-1.3812424909479102,0.25662357967972205,0.895993960666072,0.5969217612341047,1.003827461932993,0.3535111488721142,1.626234122590899,-0.9807624824831435,0.8455667360510928,-0.6596045396559488,-0.32330752252947614,0.30962364095597517,-1.051266687042697,-0.8619251071880633,1.0131278329152824,0.7045901871883101,0.5102103240087068,-0.5795087495450799,-1.4718975639160914,1.110149168791025,0.4848770449182779,-0.131034115009259,-0.8994602986777726,1.379669139856652,-0.24300620776607484,-0.032104129747120846,0.21746064790006747,-1.1751996077694868,-0.4416596710613584,1.2838430768445492,-0.33854260905174827,-0.5552927940371294,0.19992797470487422,-1.2768902810663525,-3.223132063475557,2.6814521898725237,-1.9607168460213784,1.9180731391978023,0.6077600309107104,0.4123090743791793,0.8246054475587798,-0.9596703206415195,0.2646596987299211,-0.06851920283518687,0.9944253709871688,0.24848358116043623,0.7495855784944395,-1.108429896105167,1.3753052571268305,3.18103412
class ApplicationController < ActionController::Base
...
#Problem:
#In rails 3.0.1+ it is no longer possible to do this anymore;
# rescue_from ActionController::RoutingError, :with => :render_not_found
#
#The ActionController::RoutingError thrown is not caught by rescue_from.
#The alternative is to to set a catch-all route to catch all unmatched routes and send them to a method which renders an error
#As in http://techoctave.com/c7/posts/36-rails-3-0-rescue-from-routing-error-solution
##Ruby Tutorial
#This tutorial is to help you get started with using Ruby.
#I Assume you have Ruby installed with a copy of 'irb'. If not then install RubyVersionManager and ruby 1.9.2 (instructs to follow)
#Starting with the most basic, this is a comment. Marked with the # symbol
#I will use #=> to mean the output of a command
#The Basics
1 #This is a number, more specifically a Fixnum. An Integer value without decimal.