Skip to content

Instantly share code, notes, and snippets.

View mikestratton's full-sized avatar

Mike Stratton mikestratton

View GitHub Profile
@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
@mikestratton
mikestratton / connect_twitter.php
Last active August 29, 2015 14:20
Connect to Twitter API, perform search and return results as JSON formatted data.
<?php
require_once('TwitterAPIExchange.php');
$settings = array(
'oauth_access_token' => "",
'oauth_access_token_secret' => "",
'consumer_key' => "",
'consumer_secret' => ""
);
<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!");
});
});
</script>
import java.util.Scanner;
class primeNumber {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter your input number:");
int n = scanner.nextInt();
int j = 2;
int result = 0;
while (j <= n / 2)
{
import java.util.Scanner; // initialize scanner
// Pythagorean Theorem a^2 + b^2 = c^2
public class PythagoreanTriple
{
public static void main( String[] args )
{
for ( int a = 1; a <= 500; a++ )
{
for ( int b = 1; b <= 500; b++ )
{
@mikestratton
mikestratton / salary_estimation.php
Created May 5, 2015 05:09
Salary estimation based on experience. Take experience and age of a person as input. If the person is experienced and his age is equal to or more than 35 the salary of the person is 6000. Otherwise, if the person is experienced and his age is equal to or more than 28 but less than 35, then the salary should be 4800. For experienced person below …
<?php
echo "Enter the experience:";
$exp = trim(fgets(STDIN));
echo "Enter the age of the person:";
$age = trim(fgets(STDIN));
while ($exp == 0){
$salary = 2000;
echo $salary;
exit;
@mikestratton
mikestratton / math_operators.php
Last active August 29, 2015 14:20
Math Operators: sum, difference, product, quotient, remainder, increment, decrement, greater then comparison
<?php
echo "Enter 1st number:";
$num1 = trim(fgets(STDIN));
echo "Enter 2nd number:";
$num2 = trim(fgets(STDIN));
$sum = $num1 + $num2; //sum
echo ("Sum: "."\n".$sum."\n \n");
$dif = $num1 - $num2; //difference
echo ("Difference: "."\n".$dif."\n \n");
@mikestratton
mikestratton / array_reverse.php
Created May 9, 2015 04:38
Method: array_reverse — Return an array with elements in reverse order
<?php
// using method array_reverse
echo "Enter 5 elements:";
for($i = 0 ; $i<5;$i++)
{
$arr[$i]=trim(fgets(STDIN));
}
echo "\nYour input: \n";
foreach ($arr as $value1){
@mikestratton
mikestratton / array_most_frequent.php
Created May 10, 2015 04:52
Program that finds the most frequent element in an array. (Uses methods: array_count_values, arsort, array_keys)
<?php
//Program that finds the most frequent element in an array.
$data=Array();
echo "Enter numbers:";
for($i=0;$i<6;$i++)
{
$data[$i]=trim(fgets(STDIN));;
}
// Using methods: array_count_values, arsort, array_keys
@mikestratton
mikestratton / users_tweets.php
Last active August 29, 2015 14:21
Queries twitter using specific keyword and posts most recent 100 tweets
<?php
// Queries twitter using specific keyword and posts most recent 100 tweets
error_reporting(E_ERROR);
$json = file_get_contents("http://mikestratton.net/temp/bigdatabox/src/raw_twitter_Lebron_James.php");
$t_query = json_decode($json,true);
$query = $t_query ['search_metadata']['query'];
echo "<h1>Users Tweeting About: ".$query." </h1>";
reset($t_query);