Skip to content

Instantly share code, notes, and snippets.

@gary1410
gary1410 / RockPaperScissors
Created November 18, 2013 01:47
Rock Paper Scissors in JavaScript. I should refactor this
var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice < 0.34) {
computerChoice = "rock";
} else if(computerChoice <= 0.67) {
computerChoice = "paper";
} else {
computerChoice = "scissors";
}
@gary1410
gary1410 / sessions_sign_in.rb
Last active December 26, 2015 15:19
Login Page and Sessions on the Views where users do not have to retype their information if they mistakenly mistyped information.
$LOAD_PATH.unshift(File.expand_path('.'))
require 'sinatra'
require 'sinatra/activerecord'
require_relative './models/user'
require_relative './models/post'
begin
# This loads environment variables from the .env file
require 'dotenv'
@gary1410
gary1410 / gist:7011994
Created October 16, 2013 17:52
picking an specific element and using a hover function over it.
$('.users .user:nth-child(3)').hover( function(){$(this).fadeOut(100);$(this).fadeIn(500)});
@gary1410
gary1410 / gist:7010846
Created October 16, 2013 16:35
Jquery CSS Selectors
element.style {
background-color: red;
}
coachesmedia="screen"
.container {
margin-left: auto;
margin-right: auto;
}
coachesmedia="screen"
.container, .navbar-fixed-top .container, .navbar-fixed-bottom .container {
@gary1410
gary1410 / finding a user for logins.rb
Created October 13, 2013 05:07
find_by_username (will be deprecated) or find_by
user = User.find_by_username(params[:username])
User.find_by(username: params[:username])
@gary1410
gary1410 / login.rb
Created October 13, 2013 04:48
Logging in a user in a controller
post '/signin' do
user = User.where("username = ?", params[:username])
if user.password == params[:password]
redirect "/user/#{user.id}"
else
redirect '/'
end
end
post '/signup' do
@gary1410
gary1410 / app.rb
Created October 12, 2013 22:06
Using routes and sessions without a database
require 'sinatra'
require 'erb'
require_relative 'models/coach'
enable :sessions
get '/' do
p session
@current_user = session[:user]
@fname = @current_user[:fname]
class Vehical
attr_accessor :drive, :brake
def initialize(args)
@color = args[:color]
@wheels = args[:wheels]
@status = :stopped
# @driving = false
end
def drive
class Cookie
def initialize(name,diameter)
@type = name
@size = diameter
end
def what_type_are_you?
@type
https://www.dropbox.com/s/oz32yo4yl8lewvo/Screen%20Shot%202013-08-17%20at%202.57.15%20PM.png
<?xml version="1.0" encoding="utf-8" ?>
<!-- SQL XML created by WWW SQL Designer, http://code.google.com/p/wwwsqldesigner/ -->
<!-- Active URL: http://socrates.devbootcamp.com/sql.html -->
<sql>
<datatypes db="mysql">
<group label="Numeric" color="rgb(238,238,170)">
<type label="Integer" length="0" sql="INTEGER" re="INT" quote=""/>
<type label="Decimal" length="1" sql="DECIMAL" re="DEC" quote=""/>