Skip to content

Instantly share code, notes, and snippets.

View stevenpray's full-sized avatar

Steven Pray stevenpray

  • Cincinnati, Ohio
  • 03:27 (UTC -04:00)
View GitHub Profile
#!/usr/bin/env bash
LOG_FILE=
function log() {
local LOG_TEXT="${1}"
local LOG_DATE=
LOG_DATE="$(date -u +'%Y-%m-%dT%H:%M:%S.%3NZ')"
if [ ! -z "${LOG_FILE}" ]; then
@stevenpray
stevenpray / euler92.php
Last active March 11, 2018 18:17
Project Euler 92: Investigating a square digits number chain with a surprising property. How many starting numbers below ten million will arrive at 89?
<?php
declare(strict_types=1);
ini_set('memory_limit', '1G');
ini_set('max_execution_time', '0');
/**
* Maps the given number to array of its digits.
*
* @param int $number
<?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);
'use strict';
/**
* @param {Array} arr
* @param {Function} cb
* @returns {Array}
*/
function map(a, b) {
const result = [];
'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 {string} string1
* @param {string} string2
* @returns {boolean}
*/
function isAnagram(string1, string2) {
var string1 = string1.split('').sort().join('').trim().toLowerCase();
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';
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;
<?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);
@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>