Skip to content

Instantly share code, notes, and snippets.

View PaulAndCode's full-sized avatar
🦍
Longback

Paul Liu PaulAndCode

🦍
Longback
View GitHub Profile
// ----------------------------------------------------------
// A short snippet for detecting versions of IE in JavaScript
// without resorting to user-agent sniffing
// ----------------------------------------------------------
// If you're not in IE (or IE version is less than 5) then:
// ie === undefined
// If you're in IE (>=5) then you can determine which version:
// ie === 7; // IE7
// Thus, to detect IE:
// if (ie) {}
@ariya
ariya / unsniff.js
Created October 15, 2011 00:18
PhantomJS script to check if a web page sniffs the user agent or not.
// Check if a web page sniffs the user agent or not.
var page = require('webpage').create(),
sniffing, address;
page.onInitialized = function () {
page.evaluate(function () {
window.originalNavigator = window.navigator;
@smebberson
smebberson / .gitignore
Created January 9, 2012 06:46
Express simple authentication example
node_modules
*.swp
@vishaltelangre
vishaltelangre / ie_inspector.js
Last active December 15, 2015 20:41
Fuckin' IE Detection, the "hawt" way!
// @author: Vishal Telangre <[email protected]>
// Published under MIT license.
//
// Requires: jQuery
//
// Usage:
//
// ieInspector.isIe
// -- returns
// - true for IE browsers
@mnpenner
mnpenner / screenshot.js
Last active December 5, 2019 16:08
Save a screenshot with selenium-webdriver for JavaScript
var webdriver = require('selenium-webdriver');
var fs = require('fs');
var driver = new webdriver.Builder().build();
webdriver.WebDriver.prototype.saveScreenshot = function(filename) {
return driver.takeScreenshot().then(function(data) {
fs.writeFile(filename, data.replace(/^data:image\/png;base64,/,''), 'base64', function(err) {
if(err) throw err;
});
/*global console */
/*
* In this file, we do a search for two non-existent selectors
* However the failure of only one of them contains the error we actually want
*/
(function() {
"use strict";
@lazypower
lazypower / setup.sh
Last active February 17, 2020 22:20
Setup headless chromium driver for selenium (vagrant flavor, but works with any ubuntu variant)
#!/bin/sh
set -e
if [ -e /.installed ]; then
echo 'Already installed.'
else
echo ''
echo 'INSTALLING'
echo '----------'
@homam
homam / AWS_S3_File_Upload.js
Created January 27, 2014 10:08
How to upload files to AWS S3 with NodeJS SDK
var AWS = require('aws-sdk'),
fs = require('fs');
// For dev purposes only
AWS.config.update({ accessKeyId: '...', secretAccessKey: '...' });
// Read in the file, convert it to base64, store to S3
fs.readFile('del.txt', function (err, data) {
if (err) { throw err; }
@cferdinandi
cferdinandi / umd-script-boilerplate.js
Last active December 10, 2023 10:23
A simple boilerplate for UMD JS modules.
(function (root, factory) {
if ( typeof define === 'function' && define.amd ) {
define([], factory(root));
} else if ( typeof exports === 'object' ) {
module.exports = factory(root);
} else {
root.myPlugin = factory(root);
}
})(typeof global !== "undefined" ? global : this.window || this.global, function (root) {
@cferdinandi
cferdinandi / extend.js
Last active August 17, 2024 07:57
A native JS extend() function.
/**
* Merge defaults with user options
* @private
* @param {Object} defaults Default settings
* @param {Object} options User options
* @returns {Object} Merged values of defaults and options
*/
var extend = function ( defaults, options ) {
var extended = {};
var prop;