Skip to content

Instantly share code, notes, and snippets.

View davidji99's full-sized avatar
🎯
Focusing

DJ davidji99

🎯
Focusing
View GitHub Profile
/*
The below function was derived from https://github.com/davidji99/isMobile
Please visit the link above for further instructions if needed.
*/
//paste the follow code into the Satisfy this custom JS condition field in Targeting
(function(i){var e=/iPhone/i,n=/iPod/i,o=/iPad/i,t=/(?=.*\bAndroid\b)(?=.*\bMobile\b)/i,r=/Android/i,d=/BlackBerry/i,s=/Opera Mini/i,a=/IEMobile/i,b=/(?=.*\bFirefox\b)(?=.*\bMobile\b)/i,h=RegExp("(?:Nexus 7|BNTV250|Kindle Fire|Silk|GT-P1000)","i"),c=function(i,e){return i.test(e)},l=function(i){var l=i||navigator.userAgent;this.apple={phone:c(e,l),ipod:c(n,l),tablet:c(o,l),device:c(e,l)||c(n,l)||c(o,l)},this.android={phone:c(t,l),tablet:!c(t,l)&&c(r,l),device:c(t,l)||c(r,l)},this.other={blackberry:c(d,l),opera:c(s,l),windows:c(a,l),firefox:c(b,l),device:c(d,l)||c(s,l)||c(a,l)||c(b,l)},this.seven_inch=c(h,l),this.any=this.apple.device||this.android.device||this.other.device||this.seven_inch},v=i.isMobile=new l;v.Class=l})(window);
screen.width < 1280 || isMobile.any
//end copy
@davidji99
davidji99 / Redcross.js
Last active August 29, 2015 13:56
This simple JS script, using an external site, allows you to prevent certain IPs from viewing an experiment for Optimizely Gold clients.
<script>
var myip; //declares variable to store IP address
var doNotTest = ["012.345.678.9"]; //creates an array to store IPs, separated by a comma, that shouldn't see experiment
</script>
<script type="text/javascript" src="http://l2.io/ip.js?var=myip"></script>
<script>
window.myInterval = setInterval(function() {
if ($("some-selector").length > 0) { //looks for a selector
/*
do something here
or add/or in a custom event goal like below:
*/
window['optimizely'] = window['optimizely'] || [];
$("someselector").bind("mousedown", function() {window.optimizely.push(["trackEvent", "eventName"]);
$(document).ajaxComplete(function() {
$("#someElement").html("<p>Requesting heroes!</p>"); //the action
})
window.myInterval = setInterval(function() { //sets an interval
if ($('someElement').length) { //checks if element exists. In this case, we are looking for the button element.
//add the variation code either custom written OR rom Optimizely here
clearInterval(window.myInterval); //after element has been found, clear the interval so the page doesn't load continuously
}
}, 50 )//interval timing in milliseconds;
optimizely.$(".button1").live('click', function(e) {
event.preventDefault(); //prevents the default action from triggering
var destination = optimizely.$(this).attr('href'); //stores the intended redirect URL to a variable
window.optimizely = window.optimizely || []; //activates Optimizely
window.optimizely.push(['trackEvent', 'eventName', {'revenue': 4995}]); //issues tracking call to Optimizely
# to generate your dhparam.pem file, run in the terminal
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
# Ever wanted to force a jenkins build quickly?
# Put this file in your path somewhere, and chmod +x it
curl "http://<jenkins-server-url>/buildByToken/build?job=<job-name>&token=<token>”
# Replace <vars> with your own config
# Goto your project configure page : http://<jenkins-server-url>/job/<job-name>/configure
# And set “Trigger builds remotely” to <token>
@davidji99
davidji99 / ci.coffee
Last active August 29, 2015 14:22 — forked from larrycai/ci.coffee
# Description:
# Interact with your Jenkins CI server
#
# Dependencies:
# None
#
# Configuration:
# HUBOT_JENKINS_HOST
# HUBOT_JENKINS_AUTH
#
@davidji99
davidji99 / getpost.rb
Last active August 29, 2015 14:25
Ruby HTTP/GET and HTTP/POST with auth header, pretty json
module HTTPStuff
def self.post(path, payload)
uri = construct_uri path
http = Net::HTTP.new(uri.host, uri.port)
req = Net::HTTP::Post.new(uri.path)
req.body = payload.to_json
req["Authorization"] ='SOMEAUTH'
req["Content-Type"] = "application/json"
print http.request(req)
end