Skip to content

Instantly share code, notes, and snippets.

View MAJA-Lin's full-sized avatar
💭
Looking for new opportunity

Scott Lin MAJA-Lin

💭
Looking for new opportunity
View GitHub Profile
<?php
function notModifiedCheck()
{
//get the last-modified-date of this very file
$lastModified=filemtime(__FILE__);
//get a unique hash of this file (etag)
$etagFile = md5_file(__FILE__);
//get the HTTP_IF_MODIFIED_SINCE header if set
$ifModifiedSince=(isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? $_SERVER['HTTP_IF_MODIFIED_SINCE'] : false);
@MAJA-Lin
MAJA-Lin / BasicEnum.php
Last active November 6, 2015 01:22
PHP Enumerations from stack overflow
abstract class BasicEnum {
private static $constCacheArray = NULL;
private static function getConstants() {
if (self::$constCacheArray == NULL) {
self::$constCacheArray = [];
}
$calledClass = get_called_class();
if (!array_key_exists($calledClass, self::$constCacheArray)) {
$reflect = new ReflectionClass($calledClass);
@MAJA-Lin
MAJA-Lin / gist:49b7003c5b9c18da5489
Created October 29, 2015 08:18 — forked from PowerKiKi/gist:9571aea8fa8d6160955f
PHP array_map memory usage
<?php
// Memory benchmark related to http://stackoverflow.com/questions/11657835/how-to-get-a-one-dimensional-scalar-array-as-a-doctrine-dql-query-result
// Build an array of 50 MiB
$data = [];
for ($i = 0; $i < 1024; $i++) {
$data[] = ['id' => str_repeat(' ', 1024 * 50)]; // store 50kb more
}
@MAJA-Lin
MAJA-Lin / answer_pic.go
Last active August 29, 2015 14:18 — forked from tetsuok/answer_pic.go
From tetsuok/answer_pic.go An answer for [GO:Exercise: Slices] http://tour.golang.org/moretypes/14
package main
import "code.google.com/p/go-tour/pic"
func Pic(dx, dy int) [][]uint8 {
// Allocate two-dimensioanl array.
a := make([][]uint8, dy)
for i := 0; i < dy; i++ {
a[i] = make([]uint8, dx)
}