Wednesday, 2 October 2013

php rollover link and show image form databse that has same id

php rollover link and show image form databse that has same id

I have a list of categories in a database that our echoed onto the page
like so:
echo '<li><a href=#?id='.$row['category_id'] .' "> ' .
$row['category_name'] . '</a></li>';
How would I echo that corresponding image(category_image) that is in the
database when I hover over these links individually?
Do I hide a div and then have it appear on hover with the image inside?
but then how do I transfer the id?
category_image is a path, not the actual image.

Jquery - using "this" to dynamically show and hide

Jquery - using "this" to dynamically show and hide

<div class="show_hide panel-header" rel="#panel">
<h4>Disclaimer</h4>
</div>
<div id="panel" class="panel">
<p>Lorem ipsum</p>
</div>
Above is my HTML ... a simple div for the header (event handler) and the
hidden div to show/hide. Works perfectly for a simple show/hide, but I may
have several panels on screen at once and I don't want to explicitly ID
each one and give it it's own function. How can I use the "this" selector
to achieve dynamic interactions?
My JQuery currently...
<script type="text/javascript">
$(document).ready(function(){
$(".panel").hide();
$(".show_hide").show(); //Probably don't need this line...
$('.show_hide').click(function(){
$(this).children("div").slideToggle();
});
});
</script>
Any help is appreciated. I'm new to JS/JQuery and having some trouble
understanding the different selectors. Thanks!

Admin Control / Route Issues

Admin Control / Route Issues

Right, I've been really struggling with this routing issues.
I have a nested comment section called snippet and this belongs_to :books
Please see my admin index, snippet controller & routes in that order, I've
just implemented shallow resources.
This is the current error I'm getting:
Couldn't find Book with id=2
There is only one book and it has many snippets but I think it's trying to
look for the snippet ID rather than the book on approval action. I don't
understand why?
<h3>Users</h3>
<div class="span8">
<table class="table table-condensed">
<thead>
<tr>
<th>Username</th>
<th>Email</th>
<th>Registered</th>
<th>Role</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<% @users.each do |user| %>
<tr>
<td><%= link_to user.full_name, user %></td>
<td><%= user.email %></td>
<td><%= user.created_at.to_date %></td>
<td><%= user.roles.first.name.titleize unless user.roles.first.nil?
%></td>
<td>
<a data-toggle="modal" href="#role-options-<%= user.id %>"
class="btn btn-mini" type="button">Change role</a>
<%= render user %>
</td>
<td><%= link_to("Delete user", user_path(user), :data => { :confirm
=> "Are you sure?" }, :method => :delete, :class => 'btn btn-mini')
unless user == current_user %></td>
</tr>
<% end %>
</tbody>
</div>
<div class="span8">
<table class="table table-condensed">
<thead>
<tr>
<th>Username</th>
<th>Book Created</th>
<th>Registered</th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<% @books.each do |book| %>
<tr>
<td><%= link_to book.title, book %></td>
<td><%= book.created_at.to_date %></td>
<td><%= render book %></td>
<td>Status</td>
<td><%= button_to 'Approve', active_book_path(book) %></td>
</tr>
</tr>
<% end %>
</tbody>
</div>
<div class="span8">
<table class="table table-condensed">
<thead>
<tr>
<th>Username</th>
<th>Book Created</th>
<th>Registered</th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<% @snippets.each do |snippet| %>
<tr>
<td><%= link_to snippet.body %></td>
<td><%= snippet.created_at.to_date %></td>
<td><%= render snippet %></td>
<td>Status</td>
<td><%= button_to 'Approve', active_snippet_path(snippet) %></td>
</tr>
</tr>
<% end %>
</tbody>
</div>
Snippet_controller
class SnippetsController < ApplicationController
before_filter :authenticate_user!, only: [:create], :except => [:index,
:show]
before_filter :find_book
def create
@snippet = @book.snippets.create!(params[:snippet])
redirect_to @book
end
def approve
@snippet = Snippet.find(params[:id])
if @snippet.update_attribute(:approved, true)
redirect_to users_path
else
render root_path
end
end
def edit
@snippet = @book.snippets.find(params[:id])
end
def update
@snippet = @book.snippets.find(params[:id])
respond_to do |format|
if @snippet.update_attributes(params[:snippet])
format.html { redirect_to @book, notice: 'Comment was successfully
updated.' }
else
format.html { render action: "edit" }
end
end
end
private
def find_book
@book = Book.find(params[:id])
end
end
Routes
Treebook::Application.routes.draw do
root to: 'pages#home'
post "recurly/push"
get "content/Clerk"
get "content/Author"
get "content/Editor"
match '/home' => 'pages#home'
match '/about' => 'pages#about'
match '/contact' => 'pages#contact'
match '/subscribe' => 'pages#subscribe'
match '/new' => 'pages#new'
match "books/:id/activate" => "books#approve", :as => "active_book"
match "/snippets/:id/activate" => "snippets#approve", :as => "active_snippet"
resources :books do
resources :snippets, shallow: true, :only => [:create, :edit,
:update, :destroy]
end
devise_for :admins
devise_for :users, :controllers => { :registrations => 'registrations' }
devise_scope :user do
put 'update_plan', :to => 'registrations#update_plan'
end
get "profiles/show"
as :user do
get '/register', to: 'devise/registrations#new', as: :register
get '/register1', to: 'devise/registrations#new2', as: :registernew
get '/login', to: 'devise/sessions#new', as: :login
get '/logout', to: 'devise/sessions#destroy', as: :logout
end
resources :users
as :user do
get "/login" => 'devise/sessions#new', as: :new_user_session
post "/login" => 'devise/sessions#create', as: :user_session
delete "/logout" => 'devise/sessions#destroy', as: :destroy_user_session
end
resources :user_friendships do
member do
put :accept
end
end
resources :statuses
get 'feed', to: 'statuses#index', as: :feed
end

Tuesday, 1 October 2013

Firefox cookie read event?

Firefox cookie read event?

Using observer and cookie-changedtopic, we can get to know when a cookie
is added, changed, cleared, or deleted. The script below do the same,
var httpRequestObserver_cookies = { observe: function(aSubject, aTopic,
aData) { if ("cookie-changed" == aTopic) { //cookie was added, changed,
cleared, or deleted } },
get observerService()
{
return
Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
},
register: function()
{
this.observerService.addObserver(this, "cookie-changed", false);
},
unregister: function()
{
this.observerService.removeObserver(this, "cookie-changed");
}
};
Without modifying the cookie, I want to serve modified cookie dynamically,
Is there any way to know when a cookie is read and the data passed which
can be modified?

Store a playing cards deck in MySQL (single column)

Store a playing cards deck in MySQL (single column)

I'm doing a game with playing cards and have to store shuffled decks in
MySQL.
What is the most efficient way to store a deck of 52 cards in a single
column? And save/retrieve those using PHP.
I need 6 bits to represent a number from 0 to 52 and thus thought of
saving the deck as binary data but I've tried using PHP's pack function
without much luck. My best shot is saving a string of 104 characters (52
zero-padded integers) but that's far from optimal.
Thanks.

Java installation in Ubuntu for topcoder

Java installation in Ubuntu for topcoder

Can someone help me with an issue? I want to do TopCoder&#65279;. It needs
a Java applet. I'm new to ubuntu, have the 13.04 version and have no idea
how to get Java installed and which version of it should I get for the
applet? Please suggest what to do. Thanks in advance.

Loading 10.04 onto a HP Z220 workstation

Loading 10.04 onto a HP Z220 workstation

Please help! The planned operating system is Ubuntu 10.04 with a
possibility of upgrading to Ubuntu 12.04 LRS 64bit. Trying to load version
10.04 onto our HP Z220 workstation with a Intel Core i3-3240 3.4 3M GT1 2C
CPU. Can someone please advise how we can make this work? Are we missing a
driver? Not doing it properly? Please advise.