Skip to content

Instantly share code, notes, and snippets.

id name age cured
1 Joe 27 false
2 Nick 25 false
3 Robbie 18 true
4 Romain 26 false
5 Romain 26 false
require_relative 'cookbook' # You need to create this file!
require_relative 'controller' # You need to create this file!
require_relative 'router'
require_relative 'search'
require_relative 'recipe'
require_relative 'view'
csv_file = File.join(__dir__, 'recipes.csv')
cookbook = Cookbook.new(csv_file)
controller = Controller.new(cookbook)
require_relative 'cookbook' # You need to create this file!
require_relative 'controller' # You need to create this file!
require_relative 'router'
csv_file = File.join(__dir__, 'recipes.csv')
cookbook = Cookbook.new(csv_file)
controller = Controller.new(cookbook)
router = Router.new(controller)
@Martin-Alexander
Martin-Alexander / index.html
Created December 5, 2018 20:00
JavaScript for Beginners
<button id="clickme">Click me</button>
<p id="output"></p>
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script>
// Write your JavaScript here
$("#clickme").on("click", () => {
var personsName = prompt("What is your name");
@Martin-Alexander
Martin-Alexander / exercises.js
Last active December 13, 2018 22:25
JavaScript for Beginners Exercises
// Exercise 1: Concatinate two strings
var firstName = "Alan";
var lastName = "Turing";
console.log(firstName + " " + lastName)
// Exercise 2: Filter names starting with "B"
// What's the problem with this code? We're repeating our code
@Martin-Alexander
Martin-Alexander / vs-code-settings.json
Created September 1, 2018 21:09
vs code settings
{
"terminal.integrated.cursorBlinking": true,
"terminal.integrated.fontSize": 12,
"editor.cursorStyle": "block",
"editor.renderWhitespace": "all",
"editor.roundedSelection": false,
"editor.minimap.enabled": false,
// "editor.fontFamily": "'DejaVu Sans Mono'",
"editor.fontSize": 15,
class Threater
def self.run(iterations = 1_000_000)
last_person_got_seat = 0.0
total_runs = 0.0
iterations.times do |i|
if i % 1000 == 0
print("\rNº of iterations: #{i.to_s.ljust(iterations.to_s.length)}")
end
last_person_got_seat += 1 if new.last_person_got_seat
@Martin-Alexander
Martin-Alexander / fetch-all-repos.sh
Created June 27, 2018 16:33
Download & Setup All Projects
for project_dir in */; do
cd "$project_dir"
git checkout master
git checkout -- .
git pull
bundle install
yarn install
rails db:drop db:create db:migrate db:seed
cd ..
done

Reading and Writing to CSV files in Ruby

These are the very basics of reading and writing to CSV files in Ruby. For more details and other available options consider checking out the full documentation: here


Consider a given csv file scientists.csv with the following content:

#!/bin/sh
mkdir $1 && cd $1
yarn init
yarn add webpack webpack-dev-server \
babel-core babel-preset-es2015 \
babel-loader sass-loader css-loader style-loader \
extract-text-webpack-plugin \
node-sass --dev