Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View fakefarm's full-sized avatar
🐽
🦁🍎🐸🧄🐔🍐🐹🍑🐮 🐴🦆🥦🐙🐳F🦞🧅🐶 🦧👾A🦈🐋🍉K🌽 🐣🐎🦚🦩🦔🐿🦨🐉🥕 🐿🐾🐒🍊E🐈🐻🥥🐱 🐼🥑🐷🐓🍌🐖F🦃 🐑🚜🍋🐂A🐏🌾🤖🐀🦔 R🦜🦝🐈🦓🐠🦑🦂M🐜

Dave Woodall fakefarm

🐽
🦁🍎🐸🧄🐔🍐🐹🍑🐮 🐴🦆🥦🐙🐳F🦞🧅🐶 🦧👾A🦈🐋🍉K🌽 🐣🐎🦚🦩🦔🐿🦨🐉🥕 🐿🐾🐒🍊E🐈🐻🥥🐱 🐼🥑🐷🐓🍌🐖F🦃 🐑🚜🍋🐂A🐏🌾🤖🐀🦔 R🦜🦝🐈🦓🐠🦑🦂M🐜
View GitHub Profile
@fakefarm
fakefarm / josh.js
Created April 20, 2014 01:18
remove anchor
var post = $('.wall-post-copy').first();
if (post.children().first().attr('target') == "_blank") {
post.children().first().css('display', 'none') }
@fakefarm
fakefarm / height.js
Last active August 29, 2015 14:02
Get the right height
// Get proper container height
function getContainerHeight(){
var myHeight = $('#my-header').outerHeight(),
var yourHeight = $('#deal-details').height(),
containerHeight = ( myHeight > yourHeight ? myHeight : yourHeight );
return containerHeight;
}
@fakefarm
fakefarm / meta.slim
Created June 12, 2014 21:59
meta data
= content_for :meta do
meta content=FACEBOOK['client_id'] property="fb:app_id" /
meta content=@user.url property="og:url" /
meta content=@user.short_title property="og:title" /
meta content=@user_sharing.facebook_data[:description] property="og:description" /
meta content=@user_sharing.facebook_data[:photo_url] property="og:image" /
meta content="summary" name="twitter:card" /
meta content="@lettucebooks" name="twitter:site"
meta content=@user.url name="twitter:url"
meta content=@user.short_title name="twitter:title"
@fakefarm
fakefarm / arguments_as_array.js
Last active August 29, 2015 14:04
Javascript Arguments act as array
// Arguments look like array's but are not. But you can add array functionality with prototype.
function Max(x,y,z) {
var args = Array.prototype.slice.call(arguments);
return args;
}
@fakefarm
fakefarm / indexOf.js
Last active August 29, 2015 14:04
indexOf
// Use index of to check contents of array.
// A function that takes a character (i.e. a string of length 1) and returns true if it is a vowel, false otherwise.
function isVowel(letter) {
vowels = ['a','e','i','o','u'];
var result = vowels.indexOf(letter)
if (result >= 0) {
return true;
}
else {
@fakefarm
fakefarm / sum.js
Created August 14, 2014 11:57
have some fun
function sum ( args ) {
var array, sum = 0; // Set vars
// Conditional to type check what the arguments are
if ( typeof args == 'number' ) { // If not an array, then convert it to one.
array = Array.prototype.slice.call(arguments, 0); // Gotcha, using the key word 'arguments', not the 'args' word. 'arguments' is a special word in javascript that looks like an array, but is not.
} else {
array = args;
}
for ( i in array ) { // I assume recursion could be used here if I knew how recursion worked.
@fakefarm
fakefarm / parens.md
Last active August 29, 2015 14:05
JS Parens

The moment (function(){})() made sense.

Let's start with a simple concept.

1 + 1
=> 2

Adding parens clarifies order of operations.

JS Callback AH-HA

When I told people I was confused about callbacks I often heard that callbacks were just functions. So I couldn't figure out what my hurdle was to grasping them. But I just had an AH-HA! moment after getting a better grasp on some basic syntax.

JavaScript functions use () for two different reasons. Let me recap so that we're on the same page;

2 reasons for ( )

1st | Declaration

JS return values chain well

Make an array

var a = []
=> []

And a function that returns the array

Shorthand if, else if, else (and return)

Getting comfortable with the shorthand conditional syntax. If you put the conditional on one line, the {} are not needed. Even when having multiple conditionals.

Explicit returns

return will terminate the function and spit out as it sees. No need to assign the argument to a variable.