Skip to content

Instantly share code, notes, and snippets.

@jlbruno
jlbruno / RPS.js
Last active September 13, 2022 00:11 — forked from joehinkle/RPS.js
// Initializing Variables
var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
// Validation for user input
//if ( userChoice != "rock" || "paper" || "scissors" ) {
// userChoice = prompt("You did not select rock, paper, or scissors. Please try again.");
//}
// Randomly selecting correct value for computerChoice
@jlbruno
jlbruno / angular.html
Created June 28, 2013 14:45
basic angular.js setup, which should work when code is minified.
<!doctype html>
<html class="no-js" lang="en" ng-app="AppName">
<head>
<meta charset="utf-8">
<title>Index</title>
<script type="text/javascript" charset="utf-8" src="js/angular.min.js"></script>
<script type="text/javascript" charset="utf-8" src="js/angular-mobile.min.js"></script>
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
</head>
<body>
@jlbruno
jlbruno / pre-commit
Created June 26, 2013 18:24
pre-commit hook for checking if someone is committing into a certain folder within a subversion repo, and telling them to move their commits elsewhere.
# Tell everyone to bugger off elsewhere
echo "THIS REPOSITORY HAS MOVED TO BITBUCKET" >&2
echo "https://bitbucket.org/pixelmedia/bdc-website" >&2
exit 1
# OR
# Check where in the repo they are committing, before you tell them to bugger off
LINES=$(svnlook changed $REPOS -t $TXN)
FOLDER_NAME="web-template/"
@jlbruno
jlbruno / jquery.searchFieldClear.js
Created March 21, 2013 02:31
function to add the clear functionality to input type="search"
var searchFieldClear = function() {
var public = {};
var clearButtonCss = {
cursor: 'pointer',
margin: '12px 0 0 -16px',
position: 'absolute',
zIndex: 1000
}
var buttonExists = false;

I've been finding this little meta[name='tmpl'] pattern useful lately when making template-based decisions in JS, such as when loading a particular file or set of files that are needed only on a particular page of a site.

First, in the HTML of a particular template, like say, a search result page:

<head>
  ...
  <meta name="tmpl" content="searchresult">
</head>
Turntable Chat Commands
/ Commands:
/up
/down
/me
/seriousface
/monocle
/whatever
@jlbruno
jlbruno / Avatars 1 2.js
Created March 9, 2012 03:57
viclou/Turntable-API/custom code/
//Avatars
bot.on('speak', function (data) {
// console.log('chat', data);
var text = data.text;
var name = data.name;
//PART 1
if (text.match(/^\/closeeyedgirl/)) {
bot.setAvatar ('1');
}
if (text.match(/^\/greengirl/)) {
@jlbruno
jlbruno / elementQuery-example.js
Last active September 29, 2015 23:57
elementQuery
// call elementQuery and pass it an object containing the tests.
// also pass it an object containing a 'passed' callback and a 'failed' callback
// you can also pass a bool for whether you want to bind this to be run on resize
$('#torso').elementQuery({ 'min-width' : 910 , 'max-width' : 1155}, {
passed : function() {
$(this).addClass('l-full').removeClass('l-xlarge');
},
failed : function() {
$(this).removeClass('l-full');
@jlbruno
jlbruno / ordinal.js
Last active July 28, 2022 14:58
Javascript Ordinal Numbers
// found here http://forums.shopify.com/categories/2/posts/29259
var getOrdinal = function(n) {
var s=["th","st","nd","rd"],
v=n%100;
return n+(s[(v-20)%10]||s[v]||s[0]);
}
@jlbruno
jlbruno / gist:1312723
Created October 25, 2011 13:27
Run a function after jQuery is loaded
var tempTimeout;
(function checkForJquery() {
if (!window.jQuery) {
tempTimeout = setTimeout(checkForJquery, 500);
} else {
myFunction();
clearTimeout(tempTimeout);
}
}());