Skip to content

Instantly share code, notes, and snippets.

View robotlolita's full-sized avatar
🐴
everything happens so much oh no

Quil robotlolita

🐴
everything happens so much oh no
View GitHub Profile
@robotlolita
robotlolita / gist:663335
Created November 4, 2010 22:49
Class instantiation through direct calls.
/* This is a silly simple attempt at having a object that is always
* instantiated whenever it is called directly or with the `new` keyword.
*
* It relies on `constructor`, basically. But since it uses the
* context inside the function and simply compares it's constructor with the
* current function, you can't be sure it's always going to be an
* auto-instantiation when called directly (without the new keyword), since the
* object used as context could have the same constructor as the current
* function.
*
var sDate = new Date()
, today = new Date()
, str = ""
, node;
sDate.setFullYear(2011, 0, 1);
if (sDate > today) {
str = sDate.getFullYear() }
else {
function Counter(str) {
var filter_instance = this; // keep a reference to this object's instance
this.char_count = 0; // number of unique chars found
/* return a table mapping each char to it's number of occurrences */
function count_chars() {
var array = str.split("");
var table = {};
array.map(function(elm, index, a) {
/* this function is called in the context of `array`. Which means
// your function
function calcDistance (start, end) {
var distance=9999999;
var request = {
origin:start,
destination:end,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(result, status) {
if (status == google.maps.DirectionsStatus.OK) {
For each `quote` in `Quotation` do:
Create a new DOM Node as `node`;
Set `node`'s value to `quote`;
Insert `node` in the document;
var element = document.getElementById("sum-div");
(function() {
var timer_id;
function check_visible() {
// you have access to timer_id here :3
if (element.style.display != "none")
clearInterval(timer_id);
}
function flatten(list) {
var i = 0, len = list.length;
while (i++ < len)
if (list[i] && list[i].length)
list.splice.apply(list, [i, 1].concat(flatten(list[i])));
return list;
}
HAI
WEN I SEZ CRAMPZ (LOLOBJ, URTHINGY) U
LOLOBJ DEN push(URTHINGY)
KTHX
WEN I SEZ RUNG (BUCKETZ, STARTZ, ENDZ) U
U GOTZ A GURL
IM IN UR STARTZ PIMPIN UR GURL
IZ GURL LIEK ENDZ
GTFO KTHX
function classOf(obj) {
return Object.prototype.toString.call(obj).slice(8, -1)
}
// sanitize the arguments for the `_foo` function
function foo() {
var args = [].slice.call(arguments)
, bar, baz
// get bar if it's a String
Página 1:
<form id="frmData" method="GET">
<input type="hidden" id="post-data" name="data" value="">
</form>
<script type="text/javascript">
document.getElementById("post-data").value = JSON.stringify([1,2,3])
</script>