Skip to content

Instantly share code, notes, and snippets.

View thomasfl's full-sized avatar
🏠
Working from home

Thomas Flemming thomasfl

🏠
Working from home
View GitHub Profile
import React, { ReactDOM, Component, PropTypes } from 'react';
import {render} from 'react-dom';
import { Router, Route, Link, browserHistory} from 'react-router'
/** React router hello world example **/
class App extends Component {
render() {
var Currency = React.createClass({
propTypes: {
amount: React.PropTypes.number,
currencyCode: React.PropTypes.string,
decimalPlaces: React.PropTypes.number
},
formatCurrency: function (x, decimalPlaces, decimalSeparator, groupSeparator) {
var parts = x.toString().split('.');
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, groupSeparator);
function formatCurrency(x, decimalPlaces, decimalSeparator, groupSeparator) {
var parts = x.toString().split(".");
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, groupSeparator);
if(parts.length > 1) {
parts[1] = parts[1].substring(0, decimalPlaces);
} else {
parts[1] = '000000000'.substring(0, decimalPlaces);
}
return parts.join(decimalSeparator);
}
# All purpose minimalistic random generator
def random(params)
if(params.kind_of?(Array))
return params[rand(params.size)]
end
if(params.kind_of?(Range))
return (rand(params.end - params.begin) + params.begin).to_s
end
if(params.kind_of?(Integer))
require 'thread'
require 'date'
# Format number of hours, minutes and seconds since start time:
def elapsed_time_formatted(start_time)
end_time = DateTime.now
total_seconds = ((end_time - start_time) * 24 * 60 * 60).to_i
seconds = total_seconds % 60
minutes = (total_seconds / 60) % 60
hours = total_seconds / (60 * 60)
(function (root, $$, _, Backbone) {
"use strict";
/*
backgrid
http://github.com/wyuenho/backgrid
Copyright (c) 2013 Jimmy Yuen Ho Wong and contributors
Licensed under the MIT @license.
*/
require 'rubygems'
require 'filewatcher'
filenames = ["/Users/thomasf/ruby/roman_numerals_test.rb"]
FileWatcher.new(filenames).watch(0.5) do |filename|
print "\e[2J\e[f"
puts "Reloading #{filename}"
load(filename)
MiniTest::Unit.new.run_tests
end
require 'rubygems'
require 'minitest/autorun'
class RomanNumerals
def conv(str)
1
end
end
class RomanNumeralsTest < MiniTest::Unit::TestCase
require 'rubygems'
require 'minitest/autorun'
class RomanNumerals
def conv(str)
1
end
end
class RomanNumeralsTest < MiniTest::Unit::TestCase
@thomasfl
thomasfl / minitest_autorun.rb
Created July 21, 2012 15:15
Autorun minitests fast
require 'rubygems'
require 'filewatcher'
# Autorun minitests when one of these files is updated:
files = ["my_minitest_tests.rb","code_under_test.rb"]
puts "Update one of these files to start tests: " + files.join(", ")
FileWatcher.new(files).watch do |filename|
puts "Updated " + filename
load filename