Skip to content

Instantly share code, notes, and snippets.

View jpetto's full-sized avatar
🪐

Jonathan Petto (they/them) jpetto

🪐
View GitHub Profile
@jpetto
jpetto / gist:1247995
Created September 28, 2011 13:57
C# - Get a random number between 1 and 10
// declare and assign new variable of type Random
Random r = new Random();
// declare an int & assign it a random value between 1 and 10 (inclusive)
int intRandomNumber = r.Next(10) + 1;
@jpetto
jpetto / gist:1356847
Created November 11, 2011 01:22
Intro to Programming - Quiz #3
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleQuiz3 {
class Program {
static void Main(string[] args) {
List<Pasta> pastas = Pasta.ServeDinner();
@jpetto
jpetto / gist:1903811
Created February 24, 2012 21:19
store/retrieve multiple select values to/from localstorage
// watch for changes to motivations select
$('#motivations').change(function() {
var selected = []; // create an array to hold all currently selected motivations
// loop through each available motivation
$('#motivations option').each(function() {
// if it's selected, add it to the array above
if (this.selected) {
selected.push(this.value);
}
@jpetto
jpetto / gist:2302994
Created April 4, 2012 15:44
get the largest number in a List
// declare a list of ints
List<int> ints = new List<int>();
// add some values to our list
ints.Add(13);
ints.Add(78);
ints.Add(3);
ints.Add(45);
ints.Add(22);
<?php
require_once('../app/app.db.php');
require_once('../lib/class.db.php');
// array to hold results
$results = array();
// make sure we have an action
if (array_key_exists('action', $_REQUEST)) :
$actions = explode('|', strtolower($_REQUEST['action']));
@jpetto
jpetto / js_syntax_example.js
Created August 21, 2012 20:07
JavaScript syntax example
/*
A multi-line comment
Program Description:
A script that will display an alert box on Tuesday. Hot stuff.
*/
// declare variable
var current_day;
@jpetto
jpetto / basic_html5_doc.html
Created August 21, 2012 20:32
Basic HTML5 Document
<!DOCTYPE html>
<html lang="en">
<head>
<title>Basic HTML5 Template</title>
</head>
<body>
<aside class="message">Hey, pay attention to me.</aside>
<article id="article1">
@jpetto
jpetto / dom_demo_1.html
Created August 24, 2012 20:47
DOM Demo #1
<!DOCTYPE html>
<html>
<head>
<title>DOM Demo</title>
</head>
<body>
<form id="form1">
<input type="text" id="user_name" value="" />
<button type="submit" id="submit">Get It</button>
</form>
@jpetto
jpetto / javascript_random_round.js
Created August 25, 2012 17:13
JavaScript rounding/random numbers
// declare our variables
var r, random, max = 20;
// get a random number between 0 (inclusive) and 1 (exclusive)
r = Math.random();
console.log(r);
// get a random number less than the maximum
random = max * r;
@jpetto
jpetto / javascript_string_methods_1.js
Created August 25, 2012 17:44
JavaScript string methods - 1
var name = "Nasir Jones";
// does the name contain 'Mike'?
var name_lcase = name.toLowerCase(); // converts string to lower case - easier for comparison
console.log(name_lcase); // nasir jones
var is_mike = name_lcase.indexOf('mike'); // returns the position of the given string - return -1 if not found
console.log(is_mike); // -1