This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getSeason(string $date): string { | |
$seasons = ['Winter', 'Spring', 'Summer', 'Fall']; | |
$timestamp = strtotime($date); | |
$date_year = date('Y', $timestamp); | |
return match (true) { | |
$timestamp < strtotime($date_year . '-03-21') || $timestamp >= strtotime($date_year . '-12-21') => $seasons[0], | |
$timestamp >= strtotime($date_year . '-09-23') => $seasons[3], | |
$timestamp >= strtotime($date_year . '-06-21') => $seasons[2], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function distance($lat1, $lon1, $lat2, $lon2) { | |
$theta = $lon1 - $lon2; | |
$dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta)); | |
$dist = acos($dist); | |
$dist = rad2deg($dist); | |
$miles = $dist * 60 * 1.1515; | |
return $miles; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function roundToTheNearestAnything($number) { | |
return (floor( $number / 100 ) * 100) / 10; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Auth { | |
private $ci; | |
public function __construct() { | |
$this->ci = &get_instance(); | |
} | |
public function login($username) { | |
$this->ci->session->set_userdata('username', $username); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- sh -*- | |
[user] | |
name = Mohammed Irfan | |
email = mirfan@live.in | |
[github] | |
user = mirfan | |
[core] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* mirroring code from http://www.reddit.com/r/javascript/comments/1qpjrz/succinct_one_liner_for_parsing_url_parameters/cdfjaix | |
*/ | |
location.search.slice(1) | |
.split('&') | |
.map(function (s) {return s.split('=')}) | |
.filter(function (a) {return a[1]}) | |
.reduce(function(d, e){ | |
d[e[0]] = e[1]; | |
return d; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# zsh shell functions for working in local git branches and rebasing appropriately | |
function rebase { | |
if [[ $1 == "" ]]; then master='master'; else master=$1; fi | |
branch=`git branch | grep \* | awk '{print $2}'` && | |
git co $master && git pull && git rebase $master $branch | |
} | |
function push { | |
if [[ $1 == "" ]]; then master='master'; else master=$1; fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Courtesy of: http://stackoverflow.com/a/17695576 | |
*/ | |
// Reduces one level | |
$concat = fn($x) => array_reduce($x, 'array_merge', []); | |
// We can compose $concat with itself $n times, then apply it to $x | |
// This can overflow the stack for large $n |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php /* Copyright(c) 2013 Robert Maupin. Released under the ZLIB License. */ | |
if(count($_FILES) > 0) { | |
extract($_FILES['file']); | |
list($w,$h,$type)=getimagesize($tmp_name); | |
/*see exif-imagetype() documentation :) */ | |
if(!$type||$type>3||filesize($tmp_name)>1024*200) | |
exit(); | |
$ext=image_type_to_extension($type,false); | |
$md5=md5_file($tmp_name); | |
move_uploaded_file($tmp_name,$n="img/$md5.$ext"); |