This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% if notice %> | |
<p class="notice"><%= notice %></p> | |
<% elsif alert %> | |
<p class="alert"><%= alert %></p> | |
<% end %> | |
** Add the above to the application.html.erb ** |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Cat | |
attr_reader :color, :breed, :name | |
attr_accessor :name | |
def initialize(color, breed) | |
@color = color | |
@breed = breed | |
@hungry = true | |
end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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"> |