Using __str__ after sorting

python
Question: I've created a list using class Photo and then sorted it into another list. I then want to print the string representation for just the first three items in the list. With the code I've written, I end up with a blank version of the string (like "Title:" instead of "Title: Volcano"). Where am I going wrong? Here's my code:class Photo : def __init__(self,p_d) :self.title = p_d["p"]["t"]["c"] self.tags = p_d["p"]["ts"]["t"] def t_c(self):tot = 0 for t in self.tags:tot = tot + 1 return tot def __str__(self):return "Title: {}nTags: {}".format(self.title,self.tags) p_i = [] for d in p_d_l:d2 = Photo(d) p_i.append(d2) sorted_p = [] for d in sorted(p_i, key = Photo.t_c):sorted_p.append(Photo(d)) for d in sorted_p[:3]:print(d) Answer: Read more
Read More

How to use % in python 3.x [on hold]

Uncategorized
Question: a = 42 b = 13.142783 c = "hello" d = {'x': 13, 'y': 1.54321, 'z': 'world'} e = 5628398123741234 r = "a is %d" % a # r = "a is 42" r = "%10d %f" % (a, b) # r = " 42 13.142783" r = "%+010d %E" % (a, b) # r = "+000000042 1.314278E+01" r = "%(x)-10d %(y)0.3g" % d # r = "13 1.54" r = "%0.4s %s" % (c, d['c']) # r = "hell world" r = "%*.*f" % (5, 3, b) # r = "13.143" r = "e = %d" % e # r = "e = 5628398123741234" Could you please explain the second 'r' to sixth 'r'? It is python 3.x Thank you. Answer: Read more
Read More

Urlrewrite using maven property

Uncategorized
Question: I'm trying to write a outbound rule in urlrewrite.xml that gets its value from a maven property, depending on which maven profile i'm using, like this: /web/(.*) ${urlrewrite.path} Looking in the urlrewrite.xml in the target folder, it seems to get the correct value: /web/(.*) /ecs/$1 However, when I access the page it gives me the following error: INFO: org.tuckey.web.filters.urlrewrite.substitution.VariableReplacer ERROR: function ${urlrewrite.path} type 'urlrewrite.path' not a valid type Anyone know if this is possible? Answer: Read more
Read More

How to show image in Angular 4 application read through laravel 5 rest api

Uncategorized
Question: I am using Angular 4 frontend and Laravel 5 Rest API for my application. I save and read images in Laravel using below code public function store(Request $request) { $file = $request->file('filefield'); $extension = $file->getClientOriginalExtension(); Storage::disk('local')->put($file->getFilename().'.'.$extension, File::get($file)); $entry = new Image(); $entry->mime = $file->getClientMimeType(); $entry->original_filename = $file->getClientOriginalName(); $entry->filename = $file->getFilename().'.'.$extension; $entry->save(); return response()->success(['image' => $entry]); } public function get(Image $image){ $file = Storage::disk('local')->get($image->filename); return (new Response($file, 200)) ->header('Content-Type', $image->mime); } This works fine. I am able to post and save image using Angular frontend. I am able to retrieve and see image using just the API i.e. if I open the URL myapplication/api/images/1 in the browser, I see the image. But I am having issue retrieving and showing image using Angular Here are the Angular code excerpts for the…
Read More

Laravel: Flash data in Blade file truncating double value

php
Question: Double value when sent to blade file in Laravel from controller function having 15 digits after decimal is automatically getting rounded off to only 6-7 digits after decimal when printed in blade file. Not getting the reason why is it happening so? I am sending data as follows:return redirect()->to('/list')->with('data_record', $data); The code in view file (blade) that displays the data is as follows:@foreach(session('data_record') as $item) {{$item->lat}},{{$item->lng}} @endforeach Answer: Read more
Read More

Own maven plugin with nested complex objects and default values

Uncategorized
Question: while developing some of my maven-plugins, I came upon the idea to have a more structured way to provide configurations, but I'm not sure there is a way which works. Is it possible to have a MOJO, that has instances from BaseSettings and MavenSettings used in this way, or am I forced to "polute" these fields directly into my MOJOs? import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugins.annotations.Parameter; public abstract class SomeSpecialAbstractMojo extends AbstractMojo{ @Parameter protected BaseSettings baseSettings = new BaseSettings(); @Parameter protected MavenSettings mavenSettings = new MavenSettings(); } - import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectHelper; public class MavenSettings { @Parameter(name = "project", property = "project", readonly = true, required = true) protected MavenProject project; @Component protected MavenProjectHelper projectHelper; } - import org.apache.maven.plugins.annotations.Parameter; public class BaseSettings { @Parameter(name = "skip", defaultValue…
Read More

Show a full screen slideshow image gallery Android

Uncategorized
Question: I have implemented an Android image gallery to load all the images from the Android gallery into my Android application. All the images loads fine into the application. Now I want to show a full screen slideshow of all the images that I have loaded. I am able to show a full screen slideshow, but the only problem is it is not loading the image in the current position. For example, consider I have 3 folders in my Gallery, so for the first folder, it always loads the first image, for the second folder, it always loads the second image and so on. I figured out that I am passing the position of the gridView(Folder), and I am unable to figure out how to fix this. Kindly help me…
Read More

How to supply my own custom Queue to Threadpool and add tasks to the custom queue on demand in Java?

Uncategorized
Question: How to supply my own custom Queue to Threadpool and add tasks to the custom queue on demand in Java? Imagine I have one thread and Let's say its the main thread and a thread pool (Where there are pool of threads). I want to be able to pass my own bounded queue to the thread pool such that the threads inside the thread pool can actually remove the tasks from the queue and process it. Meanwhile, I want my main thread to constantly loop and check if my bounded queue that I passed in to the thread pool is empty (queue of size == 0) and if it is add more tasks and thread pool needs to pick those up as well. I heard that if I use…
Read More

Blocking Advertisement on Firefox in Selenium

Uncategorized
Question: I want to extract colors from the webpage so I am using selenium to capture screenshot of webpage but due to advertisement coming on webpage the color pallete has unwanted colors and I have created a custom profile for firefox which uses adblock, adblock gets started on webpage load but ads still appear. This is the piece of code I am using to block ads :FirefoxProfile firefoxProfile = new FirefoxProfile(); File addonpath = new File("/Users/shubham.ga/Downloads/adblock_for_firefox-2.6.0-an+fx.xpi"); firefoxProfile.addExtension(addonpath); System.setProperty("webdriver.gecko.driver", "/Applications/Firefox.app"); driver = new FirefoxDriver(firefoxProfile); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); driver.get(url); Answer: Read more
Read More

show GridView with click button

Uncategorized
Question: I m beginner about asp.net .I have oracle database that I want when I clicked to button show result (form of result is datatable)of search in Gridview. before i was hidden. thanks for help Answer: protected void Button1_Click(object sender, EventArgs e) { GridView1.DataSource = info(id); GridView1.DataBind(); } or protected void Button1_Click(object sender, EventArgs e) { DataTable dt = new DataTable(); dt = info(id); GridView1.DataSource = dt; GridView1.DataBind(); } info method directly returns DataTable, then values are assigned to GridView. Read more
Read More

airflow UI with celery interaction not as expected

Uncategorized
Question: There's two unexpected behavior when interact with airflow UI, does anybody have some similar experience and have some insight upon them? 1. why marking a running task as success will restart the task? Try to mark a running task as success and it worked to termninate the currently task with the icon turn deep green, but later the task icon turn yellow and wait for restart again. Normally the meaning of success means no need to restart again. airflow webserver UI job status 2. Trigger a job in web UI does not work even with celery? I try to trigger a job in web UI, the reponse message shows it work and will be start at any moment, but in fact not. I check the celery worker and no…
Read More