Skip to content

Instantly share code, notes, and snippets.

View stevenpray's full-sized avatar

Steven Pray stevenpray

  • Cincinnati, Ohio
  • 12:57 (UTC -04:00)
View GitHub Profile
@stevenpray
stevenpray / form.php
Last active August 29, 2015 13:58
PHP Message Form
<?php
/**
* Message Form
*
* @author Steven Pray <steven@stevenpray.com>
* @copyright Copyright (c) 2014 Steven Pray
* @license http://www.opensource.org/licenses/mit-license.php MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
@stevenpray
stevenpray / fizzbuzz.php
Created April 16, 2014 04:01
FizzBuzz PHP
<?php
/**
* FizzBuzz
*
* A program that prints the numbers from 1 to 100.
* Multiples of three print “Fizz” instead of the number, and multiples of five print “Buzz”.
* For numbers which are multiples of both three and five print “FizzBuzz”.
*/
@stevenpray
stevenpray / fizzbuzz.c
Created April 16, 2014 04:02
FizzBuzz C
/**
* FizzBuzz
*
* A program that prints the numbers from 1 to 100.
* Multiples of three print “Fizz” instead of the number, and multiples of five print “Buzz”.
* For numbers which are multiples of both three and five print “FizzBuzz”.
*/
#include <stdio.h>
<?php
declare(strict_types=1);
ini_set('html_errors', 'false');
error_reporting(E_ALL | E_STRICT);
set_exception_handler('error');
define('DB_HOST', '127.0.0.1');
define('DB_USER', 'root');
define('DB_PASS', null);
'use strict';
function toromans(number) {
const decimals = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1];
const romans = ["M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"];
let result = '';
for (var i = 0; i <= decimals.length; i++) {
const decimal = decimals[i];
const roman = romans[i];
const remain = number % decimal;
function divide(x, y) {
if (y === 0) {
throw new Error('Division by zero');
}
var xabs = x < 0 ? -x : x;
var yabs = y < 0 ? -y : y;
var result = 0;
while (xabs >= yabs) {
result++;
xabs -= yabs;
'use strict';
/**
*
* @param {string} string1
* @param {string} string2
* @returns {boolean}
*/
function isAnagram(string1, string2) {
var string1 = string1.split('').sort().join('').trim().toLowerCase();
'use strict';
function debounce(func, wait) {
let timeout
return function (...args) {
const _this = this
clearTimeout(timeout)
timeout = setTimeout(() => func.apply(_this, args), wait)
}
}
'use strict';
/**
* @param {Array} arr
* @param {Function} cb
* @returns {Array}
*/
function map(a, b) {
const result = [];
<?php
declare(strict_types=1);
/**
* @param mixed $var
* @return bool
*/
function is_int_safe($var): bool
{
return is_numeric($var) && preg_match('/^-?\d*$/', (string)(float)$var);