Skip to content

Instantly share code, notes, and snippets.

@goldnetonline
goldnetonline / 0_reuse_code.js
Last active August 29, 2015 14:13
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
// Configuration
if (is_file('config.php')) {
require_once('config.php');
}
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<meta name="description" content="">
$file_url = 'http://www.myremoteserver.com/file.exe';
header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary");
header("Content-disposition: attachment; filename=\"" . basename($file_url) . "\"");
readfile($file_url); // do the double-download-dance (dirty but worky)
@goldnetonline
goldnetonline / bulk_chmod.sh
Created May 24, 2016 05:23
Bulk Chmod for linux servers
find ./ -type f -not -perm 644 -not -name ".ftpquota" -exec chmod 644 -c {} \;; find ./ -type d -not -perm 755 -not -group nobody -exec chmod 755 -c {} \;
@goldnetonline
goldnetonline / scroll_to_element.js
Created June 11, 2016 22:51
scrollTo Element jQuery
function scrollTo(elem) {
$('html, body').animate({
scrollTop: $(elem).offset().top
}, 'slow');
}
@goldnetonline
goldnetonline / global-variables-are-bad.js
Created June 21, 2016 11:13 — forked from hallettj/global-variables-are-bad.js
How and why to avoid global variables in JavaScript
// It is important to declare your variables.
(function() {
var foo = 'Hello, world!';
print(foo); //=> Hello, world!
})();
// Because if you don't, the become global variables.
(function() {
@goldnetonline
goldnetonline / array-shuffle.js
Created September 2, 2016 17:43
Javascript Array Shuffle
Array.prototype.shuffle = function() {
var input = this;
for (var i = input.length-1; i >=0; i--) {
var randomIndex = Math.floor(Math.random()*(i+1));
var itemAtIndex = input[randomIndex];
input[randomIndex] = input[i];
input[i] = itemAtIndex;
@goldnetonline
goldnetonline / string-format.js
Created September 2, 2016 17:45
Javascript String Format
if (!String.prototype.format) {
String.prototype.format = function() {
var args = arguments;
return this.replace(/{(\d+)}/g, function(match, number) {
return typeof args[number] != 'undefined' ? args[number] : match;
});
};
}
@goldnetonline
goldnetonline / stripstag.js
Created September 2, 2016 17:45
Javascript Strips Tag
function stripTag(html) {
var tmp = dc.createElement("div");
tmp.innerHTML = html;
return tmp.textContent || tmp.innerText || "";
}