Skip to content

Instantly share code, notes, and snippets.

View dented's full-sized avatar
🎯
Focusing

Gram dented

🎯
Focusing
View GitHub Profile
@dented
dented / efficient_dynamic_style_insert.js
Created August 24, 2015 08:47
Efficiently insert styles to page, instead of inlining each element which is more expensive
var sheet = (function() {
// Create the <style> tag
var style = document.createElement('style');
// Add a media (and/or media query) here if you'd like!
// style.setAttribute('media', 'screen')
// style.setAttribute('media', 'only screen and (max-width : 1024px)')
// WebKit hack :(
style.appendChild(document.createTextNode(''));
@dented
dented / is_native.js
Created August 24, 2015 08:45
Check if Method is Native
;(function() {
// Used to resolve the internal `[[Class]]` of values
var toString = Object.prototype.toString;
// Used to resolve the decompiled source of functions
var fnToString = Function.prototype.toString;
// Used to detect host constructors (Safari > 4; really typed array specific)
var reHostCtor = /^\[object .+?Constructor\]$/;
@dented
dented / move_files_to_individual_folders.rb
Last active August 29, 2015 14:27
Move a tree of files in a single folder to a new list of folders with individual files
require 'fileutils'
directory = './files'
new_directory = './new'
files = Dir["#{directory}/*"]
Dir.mkdir(new_directory) if !Dir.exists?(new_directory)
files.each do |file|
file_name = File.basename(file)
directory_name = File.basename(file_name, File.extname(file_name))
directory_path = "#{new_directory}/#{directory_name}"
//
// Regular Expression for URL validation
//
// Author: Diego Perini
// Updated: 2010/12/05
// License: MIT
//
// Copyright (c) 2010-2013 Diego Perini (http://www.iport.it)
//
// Permission is hereby granted, free of charge, to any person
@dented
dented / has-attribute.js
Created June 18, 2015 09:35
Has Attribute check in JavaScript on jQuery or Native
define([], function (nb) {
'use strict';
var hasAttribute = function(obj, prop) {
if (obj instanceof jQuery) {
if(obj.length > 1) throw "jQuery Array passed in";
obj = obj[0];
}
return !!obj.getAttribute(prop);
};
@dented
dented / tyga.js
Last active August 29, 2015 14:18 — forked from thebyrd/tyga.js
// Make it Nasty
function increment (i) {
i ^= (i & ~-~i) | (~i & -~i)
return i
}
@dented
dented / ArrayRemove.js
Created February 24, 2015 14:06
Remove Element of Array
// Array Remove
Array.prototype.remove = function(from, to) {
var rest = this.slice((to || from) + 1 || this.length);
this.length = from < 0 ? this.length + from : from;
return this.push.apply(this, rest);
};
@dented
dented / lost-focus.js
Last active August 29, 2015 14:02
Detect Window / Tab lost focus
(function() {
var hidden = "hidden";
// Standards:
if (hidden in document) {
document.addEventListener("visibilitychange", onchange);
} else if ((hidden = "mozHidden") in document){
document.addEventListener("mozvisibilitychange", onchange);
} else if ((hidden = "webkitHidden") in document) {
document.addEventListener("webkitvisibilitychange", onchange);
#!/bin/bash
libs=( "/usr/local/lib/libmacfuse_i32.2.dylib" \
"/usr/local/lib/libosxfuse_i32.2.dylib" \
"/usr/local/lib/libosxfuse_i64.2.dylib" \
"/usr/local/lib/libmacfuse_i64.2.dylib" \
"/usr/local/lib/libosxfuse_i32.la" \
"/usr/local/lib/libosxfuse_i64.la" \
"/usr/local/lib/pkgconfig/osxfuse.pc" )
@dented
dented / mixins.less
Created February 20, 2014 03:35
useful LESS mixins
.text-shadow (@string: 0 1px 3px rgba(0, 0, 0, 0.25)) {
text-shadow: @string;
}
.box-shadow (@string) {
-webkit-box-shadow: @string;
-moz-box-shadow: @string;
box-shadow: @string;
}
.drop-shadow (@x: 0, @y: 1px, @blur: 2px, @spread: 0, @alpha: 0.25) {
-webkit-box-shadow: @x @y @blur @spread rgba(0, 0, 0, @alpha);