Skip to content

Instantly share code, notes, and snippets.

# Battle Rules
num_knights = int(input("How many knights are available? "))
day = input("Enter the day of the week? ")
enemy = input("What enemy are we up against? ")
if enemy == "killer bunny":
print("Use the holy hand grenade!")
else:
if num_knights < 3 or day == "Monday":
print("Retreat")
"""
Same as original gist but this time using OOP.
Also use of contructors, class attributes, methods, inheritance/polymorphism etc
"""
students = []
class Student:
school_name = "Springfield Elementary"
const http = require('http');
http.createServer((request, response) => {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World!\n');
}).listen(8080);
console.log('This is my first web server on port 8080');
@benbagley
benbagley / fizzbuzz.go
Last active May 13, 2019 22:17
Three versions
package main
import "fmt"
func main() {
for i := 1; i <= 100; i++ {
if i%15 == 0 {
fmt.Println("FizzBuzz")
} else if i%3 == 0 {
fmt.Println("Fizz")
// Few FizzBuzz solutions
// for (var i = 1; i <= 100; i++) {
// var f = i % 3 == 0,
// b = i % 5 == 0;
// console.log(f ? (b ? "FizzBuzz" : "Fizz") : b ? "Buzz" : i);
// }
for (i = 0; i < 100; )
console.log((++i % 3 ? "" : "Fizz") + (i % 5 ? "" : "Buzz") || i);
class PaymentsController < ApplicationController
def create
@product = Product.find(params[:product_id])
@user = current_user
token = params[:stripeToken]
# Create the charge on Stripe's servers - this will charge the user's card
begin
byebug
charge = Stripe::Charge.create(
amount: (@product.price*100).to_i, # amount in cents, again
<% if notice %>
<p class="notice"><%= notice %></p>
<% elsif alert %>
<p class="alert"><%= alert %></p>
<% end %>
** Add the above to the application.html.erb **
@benbagley
benbagley / cat.rb
Last active October 31, 2017 17:55
class Cat
attr_reader :color, :breed, :name
attr_accessor :name
def initialize(color, breed)
@color = color
@breed = breed
@hungry = true
end
@benbagley
benbagley / calculator.html
Last active April 18, 2016 13:12
HTML Website - Introduction for CareerFoundry
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Hello World!</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">