This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string = "Hello, world!" | |
return string.slice(0, 5) + "..." | |
#=> Hello... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for (int i = 0; i < 5; i++) { | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Intelligent string truncation function | |
# written in Ruby. | |
def truncate(string, words) | |
# Define the maximum number of characters that can be used before | |
# standard truncation is applied (prevents long words from ruinning HTML). | |
max_chars = 6 * words | |
words_array = string.split(" ") # splits each word into an array ["like", "this"] | |
index = words - 1 # array indexes start at 0, so let's take one number off the words amount. | |
truncated = words_array[0..index].join(" ") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% | |
# Function to shorten a string | |
def truncate(string, characters) | |
if characters < string.length | |
truncated = string.slice(0, characters) | |
return truncated + "..." | |
else | |
return string | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Foo( callback ) { | |
this.callback = callback; | |
} | |
Foo.prototype.Bar = function() { | |
xhr = new XMLHttpRequest(); | |
xhr.onreadystatechange = function() { | |
console.log(this.callback); | |
// => undefined |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Program logic | |
function ShoppingList( options ) { | |
this.items = {}; | |
this.defaults = options.defaults; | |
if ( this.defaults ) { | |
this.items = this.defaults; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*! | |
loadCSS: load a CSS file asynchronously. | |
[c]2014 @scottjehl, Filament Group, Inc. | |
Licensed MIT | |
*/ | |
function loadCSS( href, before, media ){ | |
"use strict"; | |
// Arguments explained: | |
// `href` is the URL for your CSS file. | |
// `before` optionally defines the element we'll use as a reference for injecting our <link> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class JTask | |
# JTask.find() | |
# Retrieves records from the database file. | |
# -------------------------------------------------------------------------------- | |
# Eg: JTask.find("test.json", 1) || JTask.find("test.json", first: 10) | |
# #=> <JTask id=x, ...> | |
# -------------------------------------------------------------------------------- | |
# See wiki guide for more usage examples... | |
# https://github.com/adammcarthur/jtask/wiki/find |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class JTask | |
# JTask.find() | |
# Retrieves records from the database file. | |
# -------------------------------------------------------------------------------- | |
# Eg: JTask.find("test.json", 1) || JTask.find("test.json", first: 10) | |
# #=> <JTask id=x, ...> | |
# -------------------------------------------------------------------------------- | |
# See wiki guide for more usage examples... | |
# https://github.com/adammcarthur/jtask/wiki/find |