Skip to content

Instantly share code, notes, and snippets.

View PoTHuYJoHN's full-sized avatar

Ivan Kolodiy PoTHuYJoHN

View GitHub Profile
@PoTHuYJoHN
PoTHuYJoHN / new_gist_file
Created June 11, 2013 12:25
get natural size of image
var original = document.getElementById('forBlur'),
wO = original.naturalWidth;
@PoTHuYJoHN
PoTHuYJoHN / jcrop-init
Created June 11, 2013 12:56
init jcrop example with options
var jcrop_api = $.Jcrop(resizer.$img,{
allowResize : false,
bgFade : true,
touchSupport : true,
minSize : [w*wk,h*hk],
maxSize : [w*wk,h*hk],
onChange: function() {
$check.addClass('active');
},
onSelect: function() {
@PoTHuYJoHN
PoTHuYJoHN / gist:5766073
Created June 12, 2013 15:00
crop file with image magic and fill with black
convert 1.jpg -crop 140x300+100+200 -background black -flatten 2.jpg
@PoTHuYJoHN
PoTHuYJoHN / gist:5797261
Last active December 18, 2015 14:28
Get age from birthday in MYSQL
select *,FlOOR(DATEDIFF(NOW(), `birthdate`) / 365.25) as age FROM users
@PoTHuYJoHN
PoTHuYJoHN / gist:5804752
Last active December 18, 2015 15:29
Select user dialogs
SELECT * FROM `messages` JOIN (SELECT if(sender_id = 12, receiver_id, sender_id) AS user_id_other, MAX(cdate) as date_time_max FROM `messages` WHERE sender_id = 12 OR receiver_id = 12 GROUP BY IF(sender_id = 12, receiver_id, sender_id)) as t ON if(sender_id = 12, receiver_id, sender_id) = user_id_other AND cdate = date_time_max JOIN `users` ON `users`.id = IF(`messages`.sender_id = 12, `messages`.receiver_id, `messages`.sender_id) WHERE sender_id = 12 OR receiver_id = 12 ORDER BY cdate DESC LIMIT 11 OFFSET 0
PHP
public static function getListByUser($user_id, $limit) {
$query = "`messages`
JOIN (SELECT if(sender_id = {$user_id}, receiver_id, sender_id) AS user_id_other, MAX(cdate) as date_time_max FROM `messages`
WHERE sender_id = {$user_id} OR receiver_id = {$user_id}
GROUP BY IF(sender_id = {$user_id}, receiver_id, sender_id)) as t ON if(sender_id = {$user_id}, receiver_id, sender_id) = user_id_other
@PoTHuYJoHN
PoTHuYJoHN / gist:5965045
Created July 10, 2013 09:52
Video via iframe using Youtube and Vimeo
//VIMEO
var html = $('<iframe>', {
src: $this.attr('href'),
width: 490,
height: 270,
frameborder: 0,
webkitAllowFullScreen : '',
mozallowfullscreen: '',
allowFullScreen : ''
}).appendTo(video.$screen);
@PoTHuYJoHN
PoTHuYJoHN / gist:6000418
Created July 15, 2013 14:33
get caller of method in JS
alert(arguments.callee.caller.toString());
@PoTHuYJoHN
PoTHuYJoHN / gist:6022244
Last active December 19, 2015 21:48
Get elements from the same table where parent_id does not exists
SELECT * FROM help as t1 left JOIN help as t2 ON t1.parent_id = t2.id WHERE t2.id IS NULL AND t1.isCategory = 1
@PoTHuYJoHN
PoTHuYJoHN / preloader.js
Created July 24, 2013 08:56
Image preloader
var imgs = {
$wrap : false,
$imgs : false,
settings : {
beforeClass : 'preload',
triggerClass : 'visible',
excludeClass : '.no-preload'
},
init : function() {
var set = imgs.settings;
@PoTHuYJoHN
PoTHuYJoHN / chrome.css
Last active December 20, 2015 04:18
Chrome smooth font snippet when transform:rotate
.post-comm-submit {
position: absolute;
right: -23px;
width: 77px;
top: 24px;
-webkit-transform: rotate(-90deg) translate3d(0,0,0);
-moz-transform: rotate(-90deg);
-o-transform: rotate(-90deg);
-ms-transform: rotate(-90deg);
transform: rotate(-90deg);