HTML: autocomplete.html
<html>
<script src="http://yui.yahooapis.com/3.4.1/build/yui/yui-min.js"></script>
<script type="text/javascript">
YUI().use('autocomplete', 'autocomplete-highlighters', function(Y){
//autocomplete is available and ready to use
//add yui skin to class body so that the default
//auto complete widget skin will be applied:
Y.one('body').addClass('yui3-skin-sam');
Y.one('#search').plug(Y.Plugin.AutoComplete, {
resultHighlighter: "charMatch",
source: "query_server.php?q={query}"
});
});
</script>
<body>
search:
<input type="text" name="search" id="search">
</body>
</html>
PHP: query_server.php
<?php
$dns = 'mysql:host=127.0.0.1;dbname=test';
$usr = 'root';
$pass = '';
//PDO ==> Connection between PHP and a database server
try {
$dbh = new PDO($dns, $usr, $pass);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
$result = array();
$sql = 'SELECT * FROM favorites WHERE title LIKE :query OR url LIKE :query';
$q = $_GET['q'];
try{
$sth = $dbh->prepare($sql);
$sth->execute(array(':query' => "%$q%"));
foreach ($sth->fetchAll() as $res) {
$result[] = array("{$res['title']} {$res['url']}");
}
} catch (PDOException $ex) {}
echo json_encode($result);
?>
mysql -u root -p db_name < /path_to_sql_file/file.sql
fix:
sudo chmod 777 folder_name
body {
background-color: #000;
background-image: url(../images/bg.jpg);
background-repeat:repeat-x;
background-size: 100%;
margin: 0;
}
#menu li{
list-style-type:none; //no bullets
display:inline; //horizontal
}
Setting up alias OSX
alias are cool. Instead of typing coffee –watch –compile coffeeFile.coffee or cd ~/User/MyFavoriteFoler all the time in the terminal, you can see up your own alias.
1. To do this, you need either .bash_profile or .profile in your user folder.
a. vim ~/.bash_profile
OR
b. vim ~/.profile
*MAKE SURE you only have one of the other. Having 2 might confuse your system. If the file already exist, great! open it up
2. Go to new line, and start typing your alias!
alias ss=”cd ~/Sites”
alias coff=”coffee –watch –compile .”
3. OTHER cool stuff for profile:
a) when you do ls, all files are the same color. How unattractive. To color code folders, add:
export CLICOLOR=1
export LSCOLORS=ExFxCxDxBxegedabagacad
b) is your terminal prompt too long? ie. users-macbookair-2011-userName$
PS1=”\u$ ”
makes it so prompt only shows: userName$
credits to my awesome friend Song !! http://devnibble.blogspot.com/2011/08/setting-up-alias-osx.html
to .bash_profile or .profile add:
export CLICOLOR=cons25
export LSCOLORS=”ExGxFxdxCxDxDxhbadExEx”
<script type = "text/javascript">
(function($){ ... })(jQuery);
</script>
Anonymous function that takes a parameter $. The function is wrapped in parenthesis, but why? You see, the function in this example is an anonymous function that has no reference to itself, but by wrapping it in parenthesis, the JavaScript syntax allows us to reference to an anonymous function we just created.
So, by wrapping an anonymous function with parenthesis we can reference to that function’s memory location without actually refering to the name of that function – and well, we can’t do that because the function has no name! Furthermore, not only can we reference to a function that has no name, we can also call that function in the same statement that created it. And that’s exactly what’s going on here. The nameless function is defined, wrapped in parenthesis, and then that function is immediately called. This is only one example of the function closure usage that you will see throughout jQuery and other advanced JavaScript code.
source: http://www.authenticsociety.com/blog/jQueryPluginTutorial_Beginner
// Select all elements of class: "someClass" and
// apply a red border to all of them
jQuery(".someClass").css("border", "1px solid red");
// Select an element with id: someId and insert dynamic html into it
jQuery("#someId").html("<b>So Bold!</b>");
// Exactly the same as above, but using $
$("#someId").html("<b>So Bold!</b>");
Starting with jQuery:
$(document).ready(function(){
// Your code here
});
Inside the ready event, add a click handler to the link:
$(document).ready(function(){
$("a").click(function(event){
alert("Thanks for visiting!");
});
});
Save your HTML file and reload the test page in your browser. Clicking the link on the page should make a browser’s alert pop-up, before leaving to go to the main jQuery page.
For click and most other events, you can prevent the default behaviour – here, following the link to jquery.com – by calling event.preventDefault() in the event handler:
$(document).ready(function(){
$("a").click(function(event){
alert("As you can see, the link no longer took you to jquery.com");
event.preventDefault();
});
});