Skip to content

Instantly share code, notes, and snippets.

View xmalinov's full-sized avatar
:octocat:
Procrastination must die!

Alexander Malinov xmalinov

:octocat:
Procrastination must die!
View GitHub Profile
// ----------------------------------------------------------
// A short snippet for detecting versions of IE:
// Uses a combination of object detection and user-agent
// sniffing.
// ----------------------------------------------------------
// If you're not in IE then:
// ie === NaN // falsy
// If you're in IE then you can determine which version:
// ie === 7; // IE7
// Thus, to detect IE:
@xmalinov
xmalinov / Image To Data URI
Created July 9, 2014 11:22
Convert Image To Data URI With PHP
$str = 'This is an encoded string';
echo base64_encode($str);
$image = 'myimage.png';
$type = pathinfo($image, PATHINFO_EXTENSION);
$data = file_get_contents($image);
$dataUri = 'data:image/' . $type . ';base64,' . base64_encode($data);
//addEventListener polyfill 1.0 / Eirik Backer / MIT Licence
(function(win, doc){
if(win.addEventListener)return; //No need to polyfill
function docHijack(p){var old = doc[p];doc[p] = function(v){return addListen(old(v))}}
function addEvent(on, fn, self){
return (self = this).attachEvent('on' + on, function(e){
var e = e || win.event;
e.preventDefault = e.preventDefault || function(){e.returnValue = false}
e.stopPropagation = e.stopPropagation || function(){e.cancelBubble = true}
@xmalinov
xmalinov / gist:9c1279e0217dd6ce0f07
Last active August 29, 2015 14:05 — forked from HashNuke/gist:608259
Undo a git push
# to undo a git push
git push -f origin HEAD^:master
# to get to previous commit (preserves working tree)
git reset --soft HEAD
# to get back to previous commit (you'll lose working tree)
git reset --hard HEAD^
@xmalinov
xmalinov / gist:646607234dd180f91a85
Created September 30, 2014 13:44
Running time simple profiler
var startTime = +new Date();
/* code */
console.log(+new Date - startTime);
<link rel="stylesheet" media="all and (orientation:portrait)" href="portrait.css"/>
<link rel="stylesheet" media="all and (orientation:landscape)" href="landscape.css"/>
@xmalinov
xmalinov / 0_reuse_code.js
Last active August 29, 2015 14:08
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
git init && git add -A && git commit -m 'Initial commit'
@xmalinov
xmalinov / Social share snippet
Last active August 29, 2015 14:11
Social share snippet
/* Add id for divs with class "item" (vk, fb, tw, ok, mr)
** <div id="fb" class="item"></div>
** Uses jQuery
*/
$('.social-buttons>.item').click(function(e) {
var url = encodeURIComponent('http://somelink.ru');
var title = encodeURIComponent('Title');
var description = encodeURIComponent('Description');
var image = encodeURIComponent('http://somelink.ru/shared-image.jpg');
@xmalinov
xmalinov / Yosemite boot USB flash
Created December 19, 2014 15:04
Yosemite boot USB flash
sudo /Applications/Install\ OS\ X\ Yosemite.app/Contents/Resources/createinstallmedia --volume /Volumes/Untitled --applicationpath /Applications/Install\ OS\ X\ Yosemite.app --nointeraction