Posts

Showing posts from September 16, 2018

Simple string parser in boost::spirit::x3 not working

Image
Clash Royale CLAN TAG #URR8PPP Simple string parser in boost::spirit::x3 not working For learning purposes I'm trying to write a simple parser that accepts a string literal and puts it in a custom struct using the x3 library from boost. However, the following minimal example which is adapted from the example here does not compile. #include <iostream> #include <boost/spirit/home/x3.hpp> #include <boost/fusion/include/adapt_struct.hpp> #include <string> namespace x3 = boost::spirit::x3; namespace ast struct Symbol std::string val; ; BOOST_FUSION_ADAPT_STRUCT( ast::Symbol, val ) namespace parser x3::string("qwe"); BOOST_SPIRIT_DEFINE( symbol ); int main(int argc, char** argv) std::string input = "asd"; if (argc > 1) input = argv[1]; std::string::const_iterator begin = input.begin(); std::string::const_iterator end = input.end(); ast::Symbol sym; bool success = x3::phrase_parse(begin, end, parser::symbol, x3::ascii::space, ...

Command Line Password Prompt in PHP

Image
Clash Royale CLAN TAG #URR8PPP Command Line Password Prompt in PHP I'm writing a command line tool to help my web app. It needs a password to connect to the service. I'd like the script to show a password prompt so I don't have to pass it as a command line argument. That's easy enough, but I'd like it to not echo the password to the screen as it's typed. How can I do this with PHP? Bonus points for doing it in pure PHP (no system('stty') ) and replacing the characters with * . system('stty') * EDIT: The script will run on a unix like system (linux or mac). The script is written in PHP, and will most likely stay like that. Also, for the record, the stty way of doing it is: stty echo "Password: "; system('stty -echo'); $password = trim(fgets(STDIN)); system('stty echo'); // add a new line since the users CR didn't echo echo "n"; I'd prefer to not have the system() calls in there. system() Wha...

How do the shuffle/permute intrinsics work for 256 bit pd?

Image
Clash Royale CLAN TAG #URR8PPP How do the shuffle/permute intrinsics work for 256 bit pd? I'm trying to wrap my head around how the _mm256_shuffle_pd and _mm256_permute_pd intrinsics work. I can't seem to predict what the results of one of these operations would be. First, for _mm_shuffle_ps all is good. The results I get are the one I expect. For example: float b[4] = 1.12, 2.22, 3.33, 4.44 ; __m128 a = _mm_load_ps(&b[0]); a = _mm_shuffle_ps(a, a, _MM_SHUFFLE(3, 0, 1, 2)); _mm_store_ps(&b[0], a); // 3.33 2.22 1.12 4.44 So everything is right here. Now I wanted to try this with __m256d that is what I'm currently using in my code. From what I've found the _mm256_shuffle_ps/pd intrinsics works differently. My understanding here is that the control mask is applied two times. The first time on the first half of the 128 bit and the second on the last 128 bit. The first two pairs of control bits are used to choose from the first vector ( and store the values in t...

how can I save data to cloud firebase as number from textformfield in flutter

Image
Clash Royale CLAN TAG #URR8PPP how can I save data to cloud firebase as number from textformfield in flutter I form which contain some textformfield in which one field is price which i want to save as number not string ..below is my code of Textformfield new TextFormField( keyboardType: TextInputType.number, style: new TextStyle(fontFamily: "ChelaOne-Regular", color: Colors.white, fontSize: 20.0), decoration: new InputDecoration( labelText: "Price", labelStyle: new TextStyle( fontFamily: "ChelaOne-Regular", color: Colors.white), hintText: "Please enter Price ", hintStyle: new TextStyle( fontFamily: "ChelaOne-Regular", color: Colors.white, fontSize: 15.0)), validator: (val) => val.isEmpty ? 'Please enter Discribtion' : null, onSaved: (val) => price = val, ), my code to save data is Firestore.instance.collection('item').document().setData( "Discribtion": discribtion, "Title...

Remove “optional” keyword while displaying string - Swift

Image
Clash Royale CLAN TAG #URR8PPP Remove “optional” keyword while displaying string - Swift I am working on a movies app and it displays release date as part of the movie details on table view cell. Below is the code: let date = movieDetail.releaseDate as String let releaseDateText = NSLocalizedString("release date", comment: "Release date label text") let tbaText = NSLocalizedString("tba", comment: "TBA text") releaseDateLabel.text = "(releaseDateText): (String(describing: date != "" ? Date.getMMMddyyyyDateFormat(date) : "(tbaText)" ))" With this, I do see the date on the screen as Optional("Jan 07,2018"). I just want to display the date without optional keyword and parenthesis. Am not able to figure out what is causing "Optional" keyword to show up. Part of my app: By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and c...

Credential Provider - how to skip SAS?

Image
Clash Royale CLAN TAG #URR8PPP Credential Provider - how to skip SAS? I implemented my own custom Windows credential provider following the Windows SDK example which should let a remote application connect to a server and perform logon automatically. The problem is: the SetUsageScenario event is not called until a user presses the SAS combination (Ctrl+Alt+Del), therefore my credential provider isn't able to automatically perform the login until that happens. SetUsageScenario How does RDP do the login automatically without me pressing Ctrl+Alt+Del and logging in automatically? How do I do the same with my custom credential provider? 1 Answer 1 SAS can be skipped for Console session only if You turn it off manually in the registry/policies. RDP session always skip SAS and direct You to enter credentials. Moreover modern RDP client asks for credentials prior to establishing connection to remote server. It serialize your credentials and send them to remote server. On serve...

Create a button which duplicate elements of an array

Image
Clash Royale CLAN TAG #URR8PPP Create a button which duplicate elements of an array Hello everybody I'm new in javascript. I want to create a button which duplicate elements in an array. I try this : %a.btn.btn-success#addd :href => "#", :onclick => "duplicate(this.parentNode.parentNode)" :javascript document.getElementById('addd').click = duplicate; var i = 0; var original = document.getElementById('inf_finding.id'); function duplicate(original) var clone = original.cloneNode(true); clone.id = "inf_finding.id" + ++i; original.parentNode.appendChild(clone); But I refresh it, the element that I add is not in the page anymore.Can you help me to resolve this please ? Here are the screenshots : First It add properly the element But when I refresh the page, the element disappears. Of course, when you reload the page, everything is reset. What did you expect :) You have to implement some kind of persistence, the easie...

MPI4PY shared memory - memory usage spike on access

Image
Clash Royale CLAN TAG #URR8PPP MPI4PY shared memory - memory usage spike on access I'm using shared memory to share a large numpy array (write-once, read-many) with mpi4py, utilising shared windows. I am finding that I can set up the shared array without problem, however if I try to access the array on any process which is not the lead process, then my memory usages spikes beyond reasonable limits. I have a simple code snippet which illustrates the application here: from mpi4py import MPI import numpy as np import time import sys shared_comm = MPI.COMM_WORLD is_leader = shared_comm.rank == 0 # Set up a large array as example _nModes = 45 _nSamples = 512*5 float_size = MPI.DOUBLE.Get_size() size = (_nModes, _nSamples, _nSamples) if is_leader: total_size = np.prod(size) nbytes = total_size * float_size else: nbytes = 0 # Create the shared memory, or get a handle based on shared communicator win = MPI.Win.Allocate_shared(nbytes, float_size, comm=shared_comm) # Construct the array...

Use Linq.Dynamic or Expressions to create an new anonymous object

Image
Clash Royale CLAN TAG #URR8PPP Use Linq.Dynamic or Expressions to create an new anonymous object I've the following code: public class C public string Field get; set; public string Data get; set; var x = new C Field = "F", Data = "Data 1" ; var y = new C Field = "G", Data = "Data 2" ; And I want to cast this to an anonymous object like: var x_a = new F = "Data 1" ; var y_a = new G = "Data 2" ; Note that the property name (F or G) is the content, so this can change dynamically. I'm currently using the System.Linq.Dynamic 'Select' method for this: public static object CastToAnonymous(this C source) var objects = new List<C>(new source).AsQueryable().Select("new (Data as " + source.Field + ")") as IEnumerable<object>; return objects.First(); I'm wondering if there is an easier way to achieve this? Besides the obligatory question why you want to do this (I really lik...

java.lang.InterruptedExpectation is never thrown in body of corresponding try statement (error message)

Image
Clash Royale CLAN TAG #URR8PPP java.lang.InterruptedExpectation is never thrown in body of corresponding try statement (error message) I keep getting the error message "exception java.lang.InterruptedExpectation is never thrown in body of corresponding try statement" while (counts < 100) // Test to see if count is less than 100 try System.out.print('u000C'); counts = counts + 101; catch(InterruptedException ex) Thread.currentThread().interrupt(); How can I fix this issue Don't try to catch an exception not thrown. – shmosel 1 min ago you might add a more specific title – Adrian 1 min ago By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Kernel module probe function is never called

Image
Clash Royale CLAN TAG #URR8PPP Kernel module probe function is never called I try to load a sample device tree driver, but the probe function is never called. The entry in dts file looks like this dummy1 compatible = "ti,dummy"; reg = <0x9f200000 0x1000>, <0x9f201000 0x8>; ; And the relevant driver code is: #define DRV_NAME "dummy" static const struct of_device_id dummy_of_match = .compatible = "ti,dummy", , , ; static struct platform_driver dummy_driver = .driver = .name = DRV_NAME, .of_match_table = dummy_of_match, , .probe = dummy_probe, .remove = dummy_remove, ; MODULE_DEVICE_TABLE(of, dummy_of_match); module_platform_driver(dummy_driver); I have recompiled the dtb file (dtdiff shows it contains my device) and have copied it to target, but nothing happens when I insmod the driver. I also can't find it in /sys/firmware/devicetree/ what do you mean by copied to target ? – yashC Aug 9 at 5:58 @yashC I run kernel on beagle...

Microsoft Access - how change the label of the aggregate function “Totals” in its row

Image
Clash Royale CLAN TAG #URR8PPP Microsoft Access - how change the label of the aggregate function “Totals” in its row I've been trying to do some exercises from a book teaching on how to use MS Access (in my case 2016 version is utilized). In one of the sections, an example is given on how to perform a quick calculation using the aggregate function by clicking the "Totals" buttons from the Record group in the HOME tab, all this on a query displayed in Datasheet View with some records present. The Query in question: Now, in this query I (want to only) calculate/use the "Average" function over the "DonationValue" field values, which works. The problem is, that the label at the beginning of the row says "Total", and I cannot seem to be able change it to say something else: Even when I click over the "None" option from the falling options above, the label just remains saying "Total" (I don't know what to expect). My ...

Dynamically update html content plain JS

Image
Clash Royale CLAN TAG #URR8PPP Dynamically update html content plain JS So I have a script bound in my index.html, which literally has to fetch an array of jsons from an api, then dynamically update my page when get response. But as a result I'm getting an as the only update of my page. here is my script fetch(url) .then((resp) => resp.json()) .then((resp) => resp.results.forEach(item => fetch(item.url) .then((response)=> response.json()) .then((response) => pokeArr.push(response)) .catch(console.log) ) ).catch(console.log) const filler = () => if(!pokeArr) return 0 pokeArr.map((i,j)=> return `<tr>$i.name</tr>` ) const pokeindex = () => document.getElementById('a').appendChild(document.createElement(filler())) pokeindex() When I'm consoling it, I can see in the console all the responses I get, so I'm at least doing the fetching part right. What's parberakan ? What's pokeArr ? – T.J. Crowder Aug 8 at 12...

Returning a single value from a filter

Image
Clash Royale CLAN TAG #URR8PPP Returning a single value from a filter I am trying to return a single value from a filter that returns a large object. return data.filter(subject => subject.id === 1) .map((subject) => return subject.total.toString(); ); I have tried, toString, JSON.parse and a few more but always get it either as a single array value. [112] or a string inside the array ["112"] but not a single returned value 112 Is map the wrong method? How do I return a pure integer or string would do? The docs of filter function says that its return type is array developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… – Ionut Aug 8 at 13:05 filter array 4 Answers 4 You just need to pick the first element. This should suffice.. return data.filter(subject => subject.id === 1)[0].total+"" Good answer, thanks I prefer "find" though – leblaireau Aug 8 at 13:54 find is also more performant, because it stops as ...

Focusing in on specific areas in PyMOL from command line?

Image
Clash Royale CLAN TAG #URR8PPP Focusing in on specific areas in PyMOL from command line? I just started using PyMOL and Unix commands to look at .pdb files and I have a task that I want to perform, but I don't know exactly how to implement it. .pdb You can find the task described below: "Download this tar file and unpack it using the command line. This file contains 271 .pdb files and I want to focus in on residues numbered 40-55 in all files using PyMOL from the command line. Once those residues are focused in PyMOL, I want to save the images and export the snapshots to an html page/format." I would like to do all this using piping in Unix. I have some of the basics down but I need help with some of the more complex tasks. Any help is greatly appreciated! By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these pol...