Skip to content

Instantly share code, notes, and snippets.

View fupslot's full-sized avatar
💭
I may be slow to respond.

Eugene Brodsky fupslot

💭
I may be slow to respond.
View GitHub Profile
@fupslot
fupslot / gist:5874982
Created June 27, 2013 08:45
JavaScript: jQuery offset relative
(function($){
$.fn.offsetRelative = function(top){
var $this = $(this);
var $parent = $this.offsetParent();
var offset = $this.position();
// add scroll
offset.top += $this.scrollTop()+$parent.scrollTop();
offset.left += $this.scrollLeft()+$parent.scrollLeft();
if(!top) {
var isLeapYear = (new Date(now.getFullYear, 1, 29).getMonth() == 1); // year is leap
// returns total amount of the days that passed since Jan 1 2000
function getDay(aDate) {
if (typeof aDate === "string") {
aDate = new Date(aDate);
}
var zeroYear = 2000;
var totalYears = aDate.getFullYear() - zeroYear;
// calculate all days that passed
// since Jan 1 2000 till current time
<input type="text" class="i18n" data-labels="value#str001 placeholder#str002" />
<button class="i18n" data-labels="innerText#str003">Click Me</button>
<div class="i18n" data-labels="innerText#str004">This string will never be translated</div>
<script>
function i18n_parse (rootElement, labelAttribute, iterator) {
if (arguments.length === 1 && typeof arguments[0] === "function") {
iterator = arguments[0];
rootElement = null;
@fupslot
fupslot / gist:5023374
Created February 24, 2013 10:42
javascript: hex2rgb
function hexToRgb(hex) {
// Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF")
var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
hex = hex.replace(shorthandRegex, function(m, r, g, b) {
return r + r + g + g + b + b;
});
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result ? {
r: parseInt(result[1], 16),
@fupslot
fupslot / gist:5023373
Created February 24, 2013 10:41
javascript: rgb2hex
function rgbToHex(r, g, b) {
return "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
}
@fupslot
fupslot / gist:5015897
Created February 22, 2013 19:23
Javascript: Convert base64 to a Blob
function dataURItoBlob(dataURI, callback) {
// convert base64 to raw binary data held in a string
// doesn't handle URLEncoded DataURIs - see SO answer #6850276 for code that does this
var byteString = atob(dataURI.split(',')[1]);
// separate out the mime component
var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0]
// write the bytes of the string to an ArrayBuffer
var ab = new ArrayBuffer(byteString.length);
@fupslot
fupslot / gist:4249326
Created December 10, 2012 08:23
CSS: Sexy Button
.form-wrapper .button {
float: right;
border: 1px solid #00748f;
height: 42px;
width: 100px;
padding: 0;
cursor: pointer;
font: bold 15px Arial, Helvetica;
color: #fafafa;
text-transform: none;
@fupslot
fupslot / gist:4219524
Created December 5, 2012 21:10 — forked from JeffreyWay/gist:3185773
PHP Installation Options
./configure \
--prefix=/usr \
--mandir=/usr/share/man \
--infodir=/usr/share/info \
--sysconfdir=/private/etc \
--with-apxs2=/usr/sbin/apxs \
--enable-cli \
--with-config-file-path=/etc \
--with-libxml-dir=/usr \
--with-openssl=/usr \
@fupslot
fupslot / snippet.xml
Created November 25, 2012 21:52 — forked from JeffreyWay/snippet.xml
Laravel Resource - Sublime Text 2 Snippet
<snippet>
<content><![CDATA[
// ${1} Resource
Route::get('${1}s', array('as' => '${1}s', 'uses' => '${1}s@index'));
Route::get('${1}s/(:any)', array('as' => '${1}', 'uses' => '${1}s@show'));
Route::get('${1}s/new', array('as' => 'new_${1}', 'uses' => '${1}s@new'));
Route::get('${1}s/(:any)edit', array('as' => 'edit_${1}', 'uses' => '${1}s@edit'));
Route::post('${1}s', '${1}s@create');
Route::put('${1}s/(:any)', '${1}s@update');
Route::delete('${1}s/(:any)', '${1}s@destroy');