Skip to content

Instantly share code, notes, and snippets.

getHoverElement: function(autoBox) { //should look through the autocomplete box and find which one is hovering and return {prev: previousElement, hover: elementWithHover, next: nextElement}
//if there are no hovers the return should be {prev: firstElement, hover: null, lastElement}, if there are no elements in the box the return should be null
var items = autoBox.getElementsByTagName("li"),
m = items.length - 1,
returnValues = {
prev: null,
hover: null,
next: items[m]
};
if (m > -1) {
function attachEvent(el, action, callback){
if (el.addEventListener) {
el.addEventListener(action, callback, false);
} else if (el.attachEvent) {
el.attachEvent('on' + action, (function (ele) { return callback; })(el) );
}
}
inputKeyup: function (courseType){//event that's triggered on the input keyups
var currentRequest;
return function (e){
@marcmartino
marcmartino / Object->uiElement->note.js
Created June 28, 2012 23:28
question with proto inheritance
var uiElement = {
compiledTemplate: undefined,
template: undefined,
toHTML: function(newTemplate) {
if (typeof this.compiledTemplate !== 'function' || newTemplate) {
this.compileTemplate(newTemplate || this.template);
}
return this.compiledTemplate(this.toObjectLiteral);
},
compileTemplate: function(newTemplate) {
<?php
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache'); // recommended to prevent caching of event data.
/**
* Constructs the SSE data format and flushes that data to the client.
*
* @param string $id Timestamp/id of this connection.
* @param string $msg Line of text that should be transmitted.
*/
<script>
if (!!window.EventSource) {
var source = new EventSource('serverSentEvent.php');
} else {
// Result to xhr polling :(
}
source.addEventListener('message', function(e) {
console.log(e.data);
}, false);
@marcmartino
marcmartino / doesntwork.php
Created July 6, 2012 00:05
scope issues. $replyValue on line 4 is null, when it should be a 1 or a 0
public function markMessagesRead($mysqli, $replyValue){
$allMessages = $this->getAllMessages($mysqli);
$replyCheck = function ($message){
return $message.getAttribute($mysqli, "reply", "Reply") == $replyValue;
};
foreach(array_filter($allMessages, $replyCheck) as $messageItem){
$messageItem->setFirstViewDate($mysqli);
}
}
@marcmartino
marcmartino / insert.php
Created July 17, 2012 22:07
my insert is not inserting
$stmt = $mysqli->prepare("INSERT INTO `Quizes` (`Name`, `Course ID`, `Session ID`, `User ID`) VALUES (?,?,?,?)");
error_log($stmt->error);
$stmt->bind_param('ssss',$quizOptions['name'], $quizOptions['classID'], $quizOptions['sessionID'], $_SESSION['user_ID']);
$stmt->execute();
$returnID = $mysqli->insert_id;
$stmt->close();
@marcmartino
marcmartino / objectCourse.php
Created July 23, 2012 21:29
Catchable fatal error: object of class objectCourse could not be converted to string in /objectCourse.php on line 7
class objectCourse {
public $id;
public $subjectID;
public function loadSubjectID($mysqli) {
$stmt = $mysqli->prepare("SELECT `Subject ID` FROM `Courses` WHERE `ID` = ?");
$stmt->bind_param('s',$this->id);
$stmt->execute();
$stmt->bind_result($subjectID);
$found = false;
while($stmt->fetch()) {
@marcmartino
marcmartino / multInheritence.js
Created July 31, 2012 21:57
an attempt at multiple inheritence that feels crappy
var udemObj = {
set: function (options){
for(option in options){
if (this[option] !== undefined){
this[option] = options[option];
}
}
return this;
},
toObjectLiteral: function (){
public function getCurrentAttempt($mysqli){
include_once('global/objects/objectQuizAttempt.php');
//error_log("QUIZ INSTANCE ID: " . $this->getID());
$stmt = $mysqli->prepare("SELECT `ID` FROM `Quiz Attempts` WHERE `Quiz Instance ID` = ? ORDER BY `ID` DESC LIMIT 1");
$stmt->bind_param('s',$this->getID());
$stmt->execute();
$stmt->bind_result($attemptID);
$stmt->fetch();
$stmt->close();
error_log("QUIZ INSTANCE ID " . $this->getID() . " ATTEMPT ID: " . $attemptID);