Skip to content

Instantly share code, notes, and snippets.

View Yaffle's full-sized avatar

Viktor Yaffle

View GitHub Profile
было:
if($fitwidth>$originalsize[0]) $fitwidth=$originalsize[0];
if($fitheight>$originalsize[1]) $fitheight=$originalsize[1];
if(($h[0]/$fitwidth)>($h[1]/$fitheight))
{
$x=($originalsize[0] - $h[1]/$fitheight*$fitwidth) / 2;
$y=0;
//$fitheight=$h[1]*$fitwidth/$h[0];
}else{
<?php
function parse_mysql_dump($url) {
$handle = @fopen($url, "r");
$query = "";
while(!feof($handle)) {
$sql_line = fgets($handle);
if (trim($sql_line) != "" && strpos($sql_line, "--") === false) {
$query .= $sql_line;
if (preg_match("/;[\040]*\$/", $sql_line)) {
http://jsfiddle.net/Cyd8y/embedded/result/
function uploadImages($productId) {
//...
//изменить в шаблоне на "userfile[]" + multiple <input name="userfile[]" type="file" multiple="multiple" />
$fileName = false;
if (!isset($_FILES["userfile"])) {
return $fileName;
}
foreach ($_FILES["userfile"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
@Yaffle
Yaffle / gist:1900579
Created February 24, 2012 12:08
setTimeout + Page Visibility API
function setVisibleTimeout(callback, delay) {
var id = null,
t = 0,
prefix = '';
'o webkit moz ms'.replace(/\S+/g, function (p) {
if ((p + 'Hidden') in document) {
prefix = p;
}
});
function onVisibilityChange(event) {
@Yaffle
Yaffle / gist:1976930
Created March 5, 2012 05:46
CSRF defense
function parseUrl2($url) {
$x = parse_url($url);
if (isset($x['host'])) {
$y = explode(':', $x['host']);
$x['hostname'] = $y[0];
} else {
$x['hostname'] = null;
}
return $x;
}
html {
list-style-image: url("data:text/css;transform: scale(1.2);transition: width 0.2s, transform 0.3s;");
}
function urlify(text) { // urlify + escapeHTML
return text.replace(/([\s\S]*?)(\bhttps?:\/\/\S+|$)/g, function (p, a, b) {
b = escapeHTML(b);
return escapeHTML(a) + (b ? ('<a href="' + b + '">' + truncate(b, 48) + '</a>') : '');
});
}
String.prototype.split = function (r, limit) {
var s = String(this),
last = null,
lastIndex = null,
a = [];
limit = (limit === undefined ? -1 : limit) >>> 0;
if (!limit) {
return a;
}
if (r === undefined) {
@Yaffle
Yaffle / gist:2623011
Last active July 26, 2017 21:14
inplace merge sort
// inplace merge sort
// http://thomas.baudel.name/Visualisation/VisuTri/inplacestablesort.html
(function () {
"use strict";
var floor = Math.floor;
function lower(a, from, to, value, compare) {
while (to > from) {
var middle = from + floor((to - from) / 2);