Skip to content

Instantly share code, notes, and snippets.

View tundal45's full-sized avatar
👻
there is more to life than coding

Ashish Dixit tundal45

👻
there is more to life than coding
View GitHub Profile
// Includes functions for exporting active sheet or all sheets as JSON object (also Python object syntax compatible).
// Tweak the makePrettyJSON_ function to customize what kind of JSON to export.
var FORMAT_ONELINE = 'One-line';
var FORMAT_MULTILINE = 'Multi-line';
var FORMAT_PRETTY = 'Pretty';
var LANGUAGE_JS = 'JavaScript';
var LANGUAGE_PYTHON = 'Python';
@pjb3
pjb3 / router.rb
Created January 3, 2012 00:38
Use Ruby 1.9 Named Captures To Implement A Router
class Router
attr_accessor :routes
WILDCARD_PATTERN = /\/\*/
NAMED_SEGMENTS_PATTERN = /\/:([^$\/]+)/
NAMED_SEGMENTS_REPLACEMENT_PATTERN = /\/:([^$\/]+)/
def initialize(routes)
@routes = routes
end
require 'spec_helper'
require 'parslet/rig/rspec'
require 'tv_show_parslet'
describe TvShowParslet do
let(:parser) { described_class.new }
def p(string)
parse(string, :trace => true)
@xaviershay
xaviershay / vegan-month.md
Created November 19, 2011 17:45
Vegan Month Curriculum

Vegan Month Logo

Back in Melbourne circa 2010/11, Jodie, Jared and I used to run a [monthly vegan mentoring group][vegan-month]. I have gone back through the mailing lists and collected much of the curriculum and information from the program into this single document, so that I can distribute it more widely. The program was designed not just to get you through the first month nutritionally, but to expose you to a variety of foods and ideas that may be new to you. It emphasises that veganism is a shift sideways, not a sacrifice.

class ExampleMigration < ActiveRecord::Migration
class MyModel < ActiveRecord::Base
def some_method_i_need
# ...
end
end
def self.up
add_column :my_models, :whatever, :string
@practicingruby
practicingruby / 1_rcat_tests.rb
Last active September 27, 2015 15:47
Implementing a clone of UNIX cat in Ruby
# Task: Implement the rcat utility and get these tests to pass on a system
# which has the UNIX cat command present
# To see Gregory Brown's solution, see http://github.com/elm-city-craftworks/rcat
# Feel free to publicly share your own solutions
rrequire "open3"
working_dir = File.dirname(__FILE__)
gettysburg_file = "#{working_dir}/data/gettysburg.txt"
@jcasimir
jcasimir / performance.markdown
Created September 21, 2011 13:27
Measuring Performance

Measuring Performance

Performance is often ignored in Rails development until it becomes a problem. If ignored too long, though, it can get very tricky to improve. It's valuable to regularly audit performance and look for hotspots or design choices that are slowing things down.

Inspecting the Logs

Inspecting the log will help identify the source of several performance issues the application may have.

The Rails application log outputs the time spent processing each request. It breakdowns the time spent at the database level as well processing the view code. In development mode, the logs are displayed on STDOUT where the server is being run. In a production setting the logs will be in log/production.log within the application's root directory.

@spicycode
spicycode / tmux.conf
Created September 20, 2011 16:43
The best and greatest tmux.conf ever
# 0 is too far from ` ;)
set -g base-index 1
# Automatically set window title
set-window-option -g automatic-rename on
set-option -g set-titles on
#set -g default-terminal screen-256color
set -g status-keys vi
set -g history-limit 10000
@jcasimir
jcasimir / capybara_with_rack_test.markdown
Created September 16, 2011 00:19
Capybara with Rack::Test

Integration Testing with Capybara

Integration testing is awesome. Years ago, running integration tests was painful, slow, and they were so brittle that every change to the codebase broke the test suite.

Today it's a different story. We have amazing tools that make a tough job much easier. Let's check them out.

Background on Integration Testing

Integration tests are critically important because they exercise your application just like a real user. They therefore depend on the full stack from your models up through your controllers, helpers, view templates, web server, database, and middleware.

@ryanb
ryanb / spec_helper.rb
Created September 12, 2011 21:37
Use RSpec tags to add behavior around specs.
# Add this to your spec_helper.rb
RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true
config.around(:each, :vcr) do |example|
name = example.metadata[:full_description].downcase.gsub(/\W+/, "_").split("_", 2).join("/")
VCR.use_cassette(name, :record => :new_episodes) do
example.call
end
end
end