Posts

ruby on rails - How can I allow the user to download spreadsheets created using axlsx gem -

in controller have code create add content workbook def report p = axlsx::package.new wb = p.workbook wb.add_wordsheet(:name => "viewer summary") |sheet| sheed.add_row["lol"] end end my sheet has lot more stuff added sheet not think necessary type out. in view have button calls above report method in controller. when user clicks button want users browser download spreadsheet. possible axlsx gem? i think method looking send_data http://apidock.com/rails/actioncontroller/streaming/send_data basically this, although i'd consider removing creation , adding data wb own class. def report p = axlsx::package.new wb = p.workbook wb.add_wordsheet(:name => "viewer summary") |sheet| sheet.add_row["lol"] format.xlsx { send_data(wb) } #something similar that. end end

javascript - Angular js ng-repeat not working for server response -

i have response object server this $scope.new = {"module":"a","link":"b"} how use ng-repeat display 2 items? <div ng-repeat="item in new"> {{item}} -- {{item.module}} -- {{item.link}} </div> here's how iterate through each property within object: <div ng-repeat="(key,item) in new"> {{ key }}: {{ item }} </div> note we're using (key,item) instead of item have access key of property. plunker

Java Synchronization callstack -

suppose there synchronized method in turn calls other ordinary methods shown below: public static synchronized void dosomething(){ doit1(); } public doit1(){ doit2(); } my question is, when have above code , call dosomething(), synchronized method, method synchronized, or subsequent methods called, doit1 & doit2, synchronized? my question is, when have above code , when call dosomething() synchronized method method synchronized or subsequent methods call doit1 & doit2 synchronized ? only calls dosomething() synchronized; direct calls doit1() or others not, unless those calls use locking of kind. that is, if call doit1() , jvm won't @ call sites method , see "oh, there synchronized call site method synchronize accesses method well". in short: jvm assumes know doing.

javascript - Angular Uncaught object adding urlRouterProvider -

on config function when pass param ".config(function($urlrouterprovider)" got error uncaught object angular.min.js:6 (anonymous function) angular.min.js:6 (anonymous function) angular.min.js:34 q angular.min.js:7 f angular.min.js:33 cb angular.min.js:37 d angular.min.js:18 fc angular.min.js:18 id angular.min.js:17 (anonymous function) angular.min.js:217 angular.min.js:146 (anonymous function) angular.min.js:31 q angular.min.js:7 de.c angular.min.js:31 i've downloaded lastest version of angular , route module. i think might have forgotten include ng-route module in app. var app = angular.module('yourapp',['ngroute']);

java - Serving different CSS based on user ID - spring mvc -

i have web app developed spring-mvc. every company have admin able edit backgrounds, fonts , colors. app should store color settings( in database or in css file ?) , should use preferred css users belonging same company. different companies see different css. what best approach achieve that: serving different css based on user id. you can try code csscontroller mapping method serving css @requestmapping(value = "/mycustom.css") public @responsebody byte[] getmessages(final httpsession session, final principal principal) { stringbuffer sb = new stringbuffer(""); sb.append("/* css*/"); return sb.tostring().getbytes(charset.forname("iso-8859-1")); } and optionnaly @cacheable if need access db build css.to not have fetch data on every page. and include : <link href="/mycustom.css" rel="stylesheet">

c++ - Practical use of pointer to const -

i understand use of pointer constant strlen implementation. size_t strlen ( const char * str ); can suggest other reasons or provide scenarios 'pointer const value' useful in practice. think of way. want me @ value of variable don't want me alter variable in way, pass me constant. when use function , see parameter constant know there contract between , says should not change value of variable nor can directly. when write code don't know use functions. practice protect code. protects yourself, compiler errors moment tr change value of variable. a side note: true in c can still change value though parameter says const , take pointer alter content of variable in memory. try compiling code , notice how compiler protects making mistake. const char *cookies(const char *s) { return ('\0' == *s)? s: s + 1; } it won't let compile, why? because trying change const variable. another post same question here: const usage pointers in c ...

python - Django, ModelManager with a query based on model property -

i have models.py: class piecemanager(models.manager): def top_ten(self): # return self.get_queryset().order_by(total_likes) # how can first n-items ordered property total_likes? class piece(models.model): name = models.charfield(max_length=250) description = models.textfield(blank=true, null=true) museum = models.foreignkey(museum, blank=true, null=true) objects = piecemanager() @property def total_likes(self): return self.likes.count() class like(models.model): created_at = models.datetimefield(auto_now_add=true, blank=true, null=true) piece = models.foreignkey(piece, blank=true, null=true, related_name="likes") how can first -items ordered total_likes property? right way that? there better way? thanks. as simple search have shown, can't sort result of property or method. however in case don't need to, since can better , more efficiently aggregation: from django.db.models import ...