Canvas

<!DOCTYPE html>
<html>
<head>
</head>
<body>
	<canvas id="c" width="200" height="200"></canvas>s
	<script>
		var c = document.querySelector("#c");
		var ctx = c.getContext("2d");

		var image = new Image();

		image.onload = function(){
			console.log("Loaded image");
			ctx.drawImage(image, 0, 0, c.width, c.height);
		}

		image.src = "fry_fixed.jpg";
	</script>
</body>
</head>
</html>

jQuery

var navList, firstItem, link;

navList = $('.nav-list');
firstItem = navList.children().first();
link = firstItem.find('a');
link.attr('href','#');
var articleItems;

articleItems = $('.article-item');
articleItems.css('font-size','20px');
$('#input').on('change', function(){
  var val;
  var = $('#input').val();
  h1 = $('.articles').children('h1');
  h1.text(val);
});
var articleItems;

articleItems = $('.article-item');
ul = articleItems.find('ul');
ul.remove();
var family1, family2, bruce, madison, hunter;

family1 = $('#family1');
family2 = $('<div id="family2"><h1>Family 2</h1></div>');
bruce = $('<div id="#bruce"><h2>Bruce</h2></div>');
madison = $('<div id="#madison"><h3>Madison</h2></div>');
hunter = $('<div id="#hunter"><h3>Hunter<h3></div>');
  family2.insertAfter(family1);
  family2.append(bruce);
  bruce.append(madison);
  bruce.append(hunter);
function numberAdder(){
    var text, number;
    text = $(this).text();
    number = text.length;

    $(this).text(text + "" + number);
}
$('p').each(numberAdder);
$('#my-input').on('keypress', function(){
  $('button').remove();
});

cowsay

Redhat and CentOS users: sudo yum install cowsay
[vagrant@localhost rss]$ cowsay all is not better
 ___________________
< all is not better >
 -------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

-manual
man cowsay

var home etc tmp

min jQuery is much faster than usual jQuery.

Uppercase

function inName(name){
  name = name.trim().split(" ");
  name[1] = name[1].toUpperCase();
  name[0] = name[0].slice(0,1).toUpperCase() + name[0].slice(1).toLowerCase();

  return name[0] + " "+name[1];
}

json

JavaScript Object Notation. JSON is a popular and simple format for storing and transferring nested or hierarchal data. It’s so popular that most other programming languages have libraries capable of parsing and writing JSON (like Python’s JSON library). Internet GET and POST requests frequently pass data in JSON format. JSON allows for objects (or data of other types) to be easily encapsulated within other objects.

var education = {
  "scool": [
  {
    "name": "Echerd College",
    "city": "Saint Petersburg, FL, US",
    "degree": "BA",
    "major": ["compSci", "French"]
  },
  {
    "name": "Nova Southeastern University",
    "city": "Fort Lauderdale, FL, US",
    "degree": "Masters",
    "major": ["compSci"]
  },
  ]
};

validate json : http://jsonlint.com/

if (document.getElementsByClassName("education-entry").length === 0) {
    document.getElementById("education").style.display = "none";
}

for in loop

for(item in object){
  console.log(contry);
}

click

  $(document).click(function(loc){
    var x = loc.pageX;
    var y = loc.pageY;

    logClicks(x,y);
  });
var work = {
  "jobs": [
    {
      "employer": "Udacity",
      "title": "Course Developer",
      "location": "Mountain View, CA",
      "dates": "Feb 2014 - Current",
      "description": "Who moved my cheese cheesy feet cauliflower cheese. Queso taleggio when the cheese comes out everybody's happy airedale ricotta cheese and wine paneer camembert de normandie. Swiss mozzarella cheese slices feta fromage frais airedale swiss cheesecake. Hard cheese blue castello halloumi parmesan say cheese stinking bishop jarlsberg."
    },
    {
      "employer": "LearnBIG",
      "title": "Software Engineer",
      "location": "Seattle, WA",
      "dates": "May 2013 - Jan 2014",
      "description": "Who moved my cheese cheesy feet cauliflower cheese. Queso taleggio when the cheese comes out everybody's happy airedale ricotta cheese and wine paneer camembert de normandie. Swiss mozzarella cheese slices feta fromage frais airedale swiss cheesecake. Hard cheese blue castello halloumi parmesan say cheese stinking bishop jarlsberg."
    },
    {
      "employer": "LEAD Academy Charter High School",
      "title": "Science Teacher",
      "location": "Nashville, TN",
      "dates": "Jul 2012 - May 2013",
      "description": "Who moved my cheese cheesy feet cauliflower cheese. Queso taleggio when the cheese comes out everybody's happy airedale ricotta cheese and wine paneer camembert de normandie. Swiss mozzarella cheese slices feta fromage frais airedale swiss cheesecake. Hard cheese blue castello halloumi parmesan say cheese stinking bishop jarlsberg."
    },
    {
      "employer": "Stratford High School",
      "title": "Science Teacher",
      "location": "Nashville, TN",
      "dates": "Jun 2009 - Jun 2012",
      "description": "Who moved my cheese cheesy feet cauliflower cheese. Queso taleggio when the cheese comes out everybody's happy airedale ricotta cheese and wine paneer camembert de normandie. Swiss mozzarella cheese slices feta fromage frais airedale swiss cheesecake. Hard cheese blue castello halloumi parmesan say cheese stinking bishop jarlsberg."
    }
  ]
};

// Your code goes here! Let me help you get started

function locationizer(work_obj) {
  var locationArray = [];

  for(job in work_obj.jobs){
    var newLocation = work_obj.jobs[job].location;
    locationArray.push(newLocation);
  }
  return locationArray;
}

javascript intro

$(“#main”).append(“[name]”);

var email = "cameron@email.com";
var newEmail = email.replace("email.com","gmail.com");
console.log(email);
console.log(newEmail);

var formattedName = HTMLheaderName.replace("%data%", name);

$("#header").append(formattedName)

The prepend() method inserts specified content at the beginning of the selected elements.

var formattedName = HTMLheaderName.replace("%data%", name);
var role = "web developer";
var formattedRole = HTMLheaderRole.replace("%data%", role);

$("#header").prepend(formattedName);
$("#header").prepend(formattedRole);

var s = “audacity”;
s = s[1].toUpperCase() + s.slice(2);

var sampleArray = [0,0,7];

var incrementLastArrayElement = function(_array) {
    var newArray = [];
    newArray = _array.slice(0);
    var lastNumber = newArray.pop();
    newArray.push(lastNumber + 1);
    return newArray;
};
console.log(incrementLastArrayElement(sampleArray));

object

var bio = {
  "name":"john doe",
  "role":"web developer",
  "contacts":{
    "mobile":"080-1234-5678",
    "email": "john@example.com",
    "github":"hohndoe",
    "twitter": "@johndoe",
    "location": "San Francisco"
  },
  "welcomeMessage": "testtesttest",
  "skills": [
    "awsomenss", "delivering things", "cryogenic sleep", "saving universe"
  ],
  "bioPic": "images/fry.jpg"
}

object model

var work = {};
  work.position = "web development";
  work.employer = "more than 1000";
  work.years = "0";
  work.city = "yurakucho";

var education = {};
  education["name"] = "nova southern university"
  education["years"] = "2005-2013"
  education["city"] =  "fort lauderdale, fl, us"

$("#main").append(work.position);
$("#main").append(education.name);

create own webserver

from http.server import BaseHTTPRequestHandler, HTTPServer

class webserverHandler(BaseHTTPRequestHandler):
    def do_GET(self):
        try:
            if self.path.endswith("/hello"):
                self.send_response(200)
                self.send_header('Content-type', 'text/html')
                self.end_headers()

                output = ""
                output += "<html><body>Hello!</body></html>"
                self.wfile.write(output)
                print(output)
                return

        except IOError:
            self.send_error(404, "File Not Found %s" % self.path)

def main():
    try:
        port = 8080
        server = HTTPServer(('',port), webserverHandler)
        print("Web server running on port %s" % port)
        server.serve_forever()

    except keyboardInterrupt:
        print("^C entered, stopping web server...")
        server.socket.close()

if __name__ == '__main__':
    main()

SQLAlchemy

we must first import the necessary libraries, connect to db, and create a session to interface with the database:

from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from database_setup import Base, Restaurant, MenuItem

engine = create_engine('sqlite:///restaurantMenu.db')
Base.metadata.bind=engine
DBSession = sessionmaker(bind = engine)
session = DBSession()

Create

myFirstRestaurant = Restaurant(name = "Pizza Palace")
session.add(myFirstRestaurant)
sesssion.commit()

cheesepizza = menuItem(name="Cheese Pizza", description = "Made with all natural ingredients and fresh mozzarella", course="Entree", price="$8.99", restaurant=myFirstRestaurant)
session.add(cheesepizza)
session.commit()

firstResult = session.query(Restaurant).first()
firstResult.name

items = session.query(MenuItem).all()
for item in items:
    print item.name

Update
In order to update and existing entry in our database, we must execute the following commands:
Find Entry
Reset value(s)
Add to session
Execute session.commit()

veggieBurgers = session.query(MenuItem).filter_by(name= 'Veggie Burger')
for veggieBurger in veggieBurgers:
    print veggieBurger.id
    print veggieBurger.price
    print veggieBurger.restaurant.name
    print "\n"

UrbanVeggieBurger = session.query(MenuItem).filter_by(id=8).one()
UrbanVeggieBurger.price = '$2.99'
session.add(UrbanVeggieBurger)
session.commit()

Delete
To delete an item from our database we must follow the following steps:
Find the entry
Session.delete(Entry)
Session.commit()

spinach = session.query(MenuItem).filter_by(name = 'Spinach Ice Cream').one()
session.delete(spinach)
session.commit() 

basic認証

<?php 

switch (true){
  case !isset($_SERVER&#91;'PHP_AUTH_USER'&#93;, $_SERVER&#91;'PHP_AUTH_PW'&#93;):
  case $_SERVER&#91;'PHP_AUTH_USER'&#93; !== 'admin':
  case $_SERVER&#91;'PHP_AUTH_PW'&#93; !== 'test':
    header('WWW-Authenticate: Basic realm="Enter username and password."');
    header('Content-Type: text/plain; charset=utf-8');
    die('このページを見るにはログインが必要です');
}
header('Content-Type: text/html; charset=utf-8');

?>