Posts

php - Re-directing to certain page if logged in -

i have main page has log in link on takes user login page. however, if user logged in want take user page, example info page. i have function: function logged_in_redirect() { if (logged_in() === true) { header('location: client.php'); exit(); } } i'm wondering put this? i've tried pretty everything. if put on login page, not redirect me when logged on. i've tried adding onclick function link on home page didn't work. this logged_in() function: function logged_in() { return (isset($_session['user_id'])) ? true : false; } any suggestions? edit: i have fixed problem making button on home page link test.php file has code: <?php include 'core/init.php'; if (isset($_session["user_id"])) { header('location: client.php'); } else { header('location: info.php'); } ?> is there way around this? if session set , user authenticated work. you don't need function check wheth...

django - Recompile Python code on Raspberry Pi? -

i know might sound dummy question i'd know if python code needs recompiled or that's done (binding / rendering) server handles python code? i'm asking because i've started sample project , while adding link page got "page not found" (404 error) using urlconf defined in httpi.urls, django tried these url patterns, in order: ^$ ^piface/ current url, mypage.html, didn't match of these. you're seeing error because have debug = true in django settings file. change false, , django display standard 404 page. and python code looks like: from django.conf.urls import patterns, include, url django.conf import settings # uncomment next 2 lines enable admin: # django.contrib import admin # admin.autodiscover() urlpatterns = patterns('', url(r'^$', 'httpi.views.index'), url(r'^/mypage.html', 'httpi.views.index'), url(r'^piface/', include('httpiface.urls')), # uncomment admin/doc l...

ios - Compressing an NSKeyedArchiver file that included UIImageView with loaded image -

i have view uiimageview. loaded either jpg or png image format. says jpg image version has data size of 100k. used nskeyedarchiver save view file. size of file getting 3mb. if used png version of image, archived file still around 3mb. i used zlib compress archived file. not seem have effect. anything can close as possible 100k area? btw: if used uiwebview load image, jpg version of image archived file's close original jpg's. edit: matt's answer gave me idea, ended doing: note: arleady used subclass of uiimageview create ivar hold nsdata image in encodewithcoder before calling [super encodewithcoder...] , set self.image = nil ; , set self.image image data using saved nsdata in 1. make sure encode nsdata ivar in 1. in initwithcoder , using nsdata ivar restore image. you don't need keyed archiver this. if image came inside app, you've got image file, there's nothing save; archive image's name. if image came fro...

php - Time ago function accuracy -

i have function in gets date post , supposed write how long ago posted. when use function says posted 43 years , 4 months ago odd reason. function relativetime($date,$precision=2) { $times=array(365*24*60*60 => "year", 30*24*60*60 => "month", 7*24*60*60 => "week", 24*60*60 => "day", 60*60 => "hour", 60 => "minute", 1 => "second"); $passed=time()-$date; if($passed<5) { $output='less 5 seconds ago'; } else { $output=array(); $exit=0; foreach($times $period=>$name) { if($exit>=$precision || ($exit>0 && $period<60)) break; $result = floor($passed/$period); if($result>0) { $output[]=$result.' '.$name.($result==1?'':'s'); $passed-=$re...

Encode string as HTML in Ruby with tags intact -

this question has answer here: how encode/decode html entities in ruby? 7 answers how encode strings html keep tags intact? eg <div id='blah'>i brown fox > > </div> becomes <div id='blah'>i brown fox &gt; &gt; </div> why not use xml/html builder nokogiri? simply install gem. gem install nokogiri the following little script created based on provided in question: require 'nokogiri' builder = nokogiri::html::builder.new |doc| doc.div(:id => 'blah') { doc.text "i brown fox > >" } end puts builder.to_html gives following html snippit. <!doctype html public "-//w3c//dtd html 4.0 transitional//en" "http://www.w3.org/tr/rec-html40/loose.dtd"> <div id="blah">i brown fox &gt; &gt;<id>hello</...

opengl - Best algorithm for ray picking through a lot of spheres -

Image
in opengl application have lot of spheres (more 100.000) , i'm willing implement efficient ray-picking algorithm. my approach far naive one: calculate ray (in object space) corresponding mouse pointer , intersect each sphere have ray. while approach may fast enough application (the actual rendering of spheres can become slower picking them ray...), wondering best approaches out there kind of situation. i'm concerned fact sphere may have arbitrary radius, , don't know how take account in space partitioning structure such octree. do have suggestion? i'll add more details: the application in question molecular viewer atoms represented spheres such in picture: spheres can overlap partially or completely. scene can dynamic (you can molecular simulation), don't want pick during animation. ideally, find solution can extended cylinders in future. interesting question! ray vs sphere collision test 1 of simple , why spheres used in determining...

java - Syntactical issue using generics -

this homework problem: i have generic class defined follows: public class priorityqueue<t extends comparable<t>> { arraylist<t> queue; public priorityqueue(){ queue = new arraylist<>(); } void add(t t){ queue.add(t); collections.sort(queue); } <t extends comparable<t>> t remove(){ t t = queue.get(0); queue.remove(t); return t; } } but netbeans showing following error (red-underline) on line t t = queue.get(0) : incompatible types required: t#2 found: t#1 t#1,t#2 type-variables: t#1 extends comparable<t#1> declared in class priorityqueue t#2 extends comparable<t#2> declared in method <t#2>remove() it seems though somehow it's not understanding t type i'm referring in method declaration same 1 referred in type parameter of class. i'm guessing sort of syntax issue. i wonder if i'm overcomplicating things - seem more logical me if declared method t remove() { . compiles...