Skip to content

Instantly share code, notes, and snippets.

View mikestratton's full-sized avatar

Mike Stratton mikestratton

View GitHub Profile
@mikestratton
mikestratton / ISBN-10
Created April 7, 2015 02:55
ISBN-10 Validation Written in PHP
<?php
echo"Enter the ISBN number: ";
$isbn = trim(fgets(STDIN));
$isbn_length = strlen($isbn); //length
if (10 != $isbn_length) //ISBN length = 10?
{ echo "Not Valid";
exit;
}
$arr1 = str_split($isbn); // to array
$m0 = $arr1[0] * 10;
@mikestratton
mikestratton / Pseudo Code
Last active August 29, 2015 14:18
Pseudo code for the 2015 Space Apps Challenge
// Pseudo Code for Data Treasure Hunting
// NASA's SpaceAppsChallenge 2015
// Pseudo Code Derived from:
// MESSAGE POSTED IN NASA STARTER KIT
// Posted by Alon Peled, Ph.D.(Harvard University)
// FILE: NASA_starter_kit/xl/sharedStrings.xml
Dear NASA Data Treasure Hunt Participant,
1. Develop system to discover new keywords
#!/usr/bin/python
import re
file=open("HAWAII_GOV_readout_ANSI.txt","r+")
wordcount={}
for word in file.read().split():
#remove alphanumeric characters and underscores
word = re.sub('[^\w]', '', word)
@mikestratton
mikestratton / gist:721c69f96090c137e81f
Created April 18, 2015 01:52
Input/Output in same page.
<html>
<head>
<script src="http://code.jquery.com/jquery-2.1.3.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#submit").click(function(){
var postInputVal = $("#postinput").val();
$("#postecho").val(postInputVal);
console.log("OK!");
});
@mikestratton
mikestratton / tweetpost.php
Created April 20, 2015 06:27
Connect & tweet to twitter using TwitterOAuth & Composer!
<?php
//Use the force, Luke: https://twitteroauth.com/
require "vendor/autoload.php";
use Abraham\TwitterOAuth\TwitterOAuth;
$twitterConnection = new TwitterOAuth(
'', //Consumer Key
'', //Consumer secret
'', //Access token
'' //Access token secret
@mikestratton
mikestratton / gettype.php
Last active August 29, 2015 14:19
identify the data type of a $value using gettype function
<?php
// identify the data type of a $value using gettype function
// http://php.net/manual/en/function.gettype.php
$json = file_get_contents("http://mikestratton.net/temp/bigdatabox/tweetjson_RAW.php");
$t_query = json_decode($json,true);
$name = $t_query ['statuses'][0]['user']['name'];
$screen = $t_query ['statuses'][0]['user']['screen_name'];
$text = $t_query ['statuses'][0]['text'];
$query = $t_query ['search_metadata']['query'];
@mikestratton
mikestratton / suicide_counter.php
Last active August 29, 2015 14:20
Unix Time Stamp
<?php
$unix = new DateTime(); //Unix Time Stamp (seconds since Jan 01 1970. (UTC))
$unix_ts = $unix->getTimestamp();
$now = $unix_ts - 1420070400; //seconds between Unix Time Stamp and Jan 1 2015(UTC)
$y_sui_tot = $now / 766.385574378; //suicide occurs every 766 seconds
$f_sui = number_format($y_sui_tot);
echo "<h1>Total Suicides in 2015: <br/>".$f_sui."</h1>";
$y_sui_att = 25 * $y_sui_tot; // 25 suicide attempts before fatality
@mikestratton
mikestratton / helloworld
Created April 29, 2015 12:28
Ruby Hello World in One LIne
puts("Hello World!")
@mikestratton
mikestratton / user_input
Created May 4, 2015 06:37
Input 2 numbers from user, perform calculation and print results.
#!/usr/bin/ruby
# Request 2 numbers from user and perform calculation
print "Enter value of a: "
a = gets
print "Enter value of b: "
b = gets
print " a = " + a
print " b = " + b
print "b - a + 100 = " , (b.to_i - a.to_i + 100)
@mikestratton
mikestratton / exam_result
Created May 4, 2015 09:25
Input student score and outputs grade results with message.
#output grade results dependent on student score
puts "Enter the students score: "
score = gets.to_i
while score > 100
puts "You must enter a number less then or equal to 100 "
puts "Enter the students score: "
score = gets.to_i
end
while score == 100