Posts

ruby on rails - Is it correct architecture for adding user's posts? -

create action in posts controller: def create @post = current_user.posts.build(post_params) if @post.not_exists?(current_user) if @post.save #flash redirect_to root_path else #flash[:error] redirect_to root_path end else #flash[:error] redirect_to root_path end end post model: class post < activerecord::base belongs_to :user ##validations def not_exists?(user) return true unless user.posts.find_by(name: self.name) end end my question: correct build create action this? or there better architectural design? think fat action. why not use validation instead ? class post < activerecord::base belongs_to :user validates_uniqueness_of :name, :scope => :user_id

android - How can I make HttpClient works faster? -

i have application posts , gets php , mysql server. used function actions took 5 seconds. used httpparams didn't work, too. is there way make faster? string responsebine(){ log.d("destpek wext",""); try{ httpclient httpclient = new defaulthttpclient(); httpget httpget= new httpget(urlindex); if(logged) { httpresponse rs = httpclient.execute(teketin.httppost, localcontext); entityutils.tostring(rs.getentity()); rs = httpclient.execute(httpget, localcontext); entityutils.tostring(rs.getentity()); } responsehandler = new basicresponsehandler(); string rsp = new string(httpclient.execute(httpget, responsehandler).getbytes("iso-8859-1"),"utf-8"); return rsp; }catch(exception e){ system.out.println("exception : " + e.getmessage()); } log.d("destpek wext",""); return "...

html - CSS/JavaScript: Liquid Design issue -

i'm trying make website similar one. on website use javascript change padding on first section keep in windows viewport. have done this, have issue making button move way theirs move when window size changed. see video below, when make height smaller (to extent) button should move up, on copy doesn't can't figure out how have done it. video below shows css code , html , no values seem changes javascript make button move, does, padding of element doesn't change 96. youtube video edit: code far, html: <body> <div class="container"> <section id="header" class="arrows" style="padding:280px 0px"> <header> <h1>mobile paint solutions</h1> <p>since 1980</p> </header> <footer> <a onclick="test()" href="" class="button white">about</a...

java - Thread safe access to arraylist: two producer one consumer. Lock object is enough? -

i have 2 thread can produce value , add in arraylist, , other thread can access read value. my problem producer can access list in same time consumer use data. this code : public class commandtree { lock lock = new reentrantlock(); arraylist<command> cmdtosend = null; jsonobject sendcmdmap; public commandtree(jsonobject sendcmdmap) { this.cmdtosend = new arraylist<command>(); this.sendcmdmap = sendcmdmap; } private synchronized void addmacrocmd(string macro, int fmt, int tgt, int sid,int count,jsonarray sli,string paramname,jsonobject params,int function) { boolean check = false; int = 0; lock.lock(); try { for(i=0; i<cmdtosend.size(); i++) { if(cmdtosend.get(i).getmacroname().equalsignorecase(macro)) { check = true; break; } } if(check == false) { cmdto...

javascript - Log how many people visited my site? -

is possible find out, how many people have visited website? javascript or html. if user on website, should count +1 or sth that. have no idea , have not tried yet. guys :) try use code in php: <? session_start(); $today = time(); $query="insert logged_in (today, sessionid, currentpage, browsertype, ip) values ('".$today."','".$_session['sesid']."','".$_server['php_self']."','".$_server['http_user_agent']."','".$_server['remote_addr']."')"; $result = mysql_query($query); ?> but need logged_in table. hope you!

c# - Dynamically adjust ListView height on adding / removing items? -

Image
i have 3 level nested listview binded same 3 level nested collection. mainitems added @ 3rd level. unmodified, there scrollbars on all levels. on item added, edit containing grid of listviewitem adjust height dynamically. i have succeeded on removing 3rd level scroll bar . however, want remove 2nd level also, can't seem do. when try adjust height of 1st level listviewitem , scrollbars on 1st level disappears height not adjusted @ all. what want only have scrollbar on 1st level , scroll there. basically, this: this current code: <grid x:name="parentgrid"> <listview x:name="level1listview" itemssource="{binding path=level1}"> <listview.itemtemplate> <datatemplate> <grid x:name="gridlevel1"> <grid.columndefinitions> <columndefinition width="auto" /> <columndefinition width="*...

oracle - Object not exists error while using TABLE expression -

here code: quite straight forward.. create or replace package types type rec record ( employee_id number, fname varchar2(20) ); type tab_rec table of rec; type tab_numbers table of number; type tab_chars table of varchar2(10); end types; / create or replace function get_employees_rec ( o_error_msg in out varchar2, l_access_tab out types.tab_chars ) return boolean --o_access_tab types.tab_chars; cursor c_rec select first_name employees; begin open c_rec; fetch c_rec bulk collect l_access_tab; close c_rec; return true; exception when others o_error_msg:=substr(sqlerrm,1,100); return false; end; / declare o_error_msg varchar2(100); l_access types.tab_chars; begin if get_employees_rec(o_error_msg,l_access)=false dbms_output.put_line('got you'); end if; rec in(select * employees e,table(l_access) f value(f)=e.first_name) loop dbms_output.put_line(rec.first_na...