天道酬勤,学无止境

技术分享

moment.js date validation from array of formats

Question I need to test an input for proper date format. I want to accept several date formats so I created a validating function that test if at least one of the formats is OK and in that case return true. I use moment.js to test the date. When I simply type the condition with hard-coded string date formats, the function works properly: var multiDateValidator = function (value) { if ((moment(value, 'DD/MM/YYYY', true).isValid()) || (moment(value, 'D/M/YYYY', true).isValid()) || (moment(value, 'DD.MM.YYYY', true).isValid()) || (moment(value, 'D.M.YYYY', true).isValid()) || (moment(value, 'DD

2022-07-11 10:01:53   javascript   momentjs

ERROR: The requested URL could not be retrieved

Question I have a project in CodeIgniter and hosted in Sub-domain, and it has an error: The requested URL could not be retrieved Here is a picture of it: Error Answer1 I had the same error on a new installation of CodeIgniter. I solved this error by turning off my VPN browser plugin. You might have a proxy or VPN app running turn it off and see. Answer2 Please use this mandatory part before moving your code from localhost to live server. Change base_url in config file. Do necessary changes in .htaccess file Change database connection credentials This will help you. Answer3 Below steps worked

2022-07-11 10:01:45   php   codeigniter   cpanel

Test if a variable is read-only

Question To test if a variable is read-only, there are the following ugly hacks: # True if readonly readonly -p | egrep "declare -[:lower:]+ ${var}=" # False if readonly temp="$var"; eval $var=x 2>/dev/null && eval $var=\$temp Is there a more elegant solution? Answer1 Using a subshell seems to work. Both with local and exported variables. $ foo=123 $ bar=456 $ readonly foo $ echo $foo $bar 123 456 $ (unset foo 2> /dev/null) || echo "Read only" Read only $ (unset bar 2> /dev/null) || echo "Read only" $ $ echo $foo $bar 123 456 # Still intact :-) The important thing is that even is that the

2022-07-11 10:01:42   bash

How to Set an existing ECS cluster to a compute environment in AWS Batch

Question I have an ECS cluster running in my environment and it is configured with tasks, repositories and services and autoscaling. I am discovering the AWS Batch service and when I create a new compute environment a new cluster is being added to the ECS service. I want to know how to set a compute environment to my already existing cluster? Answer1 I know this is quite an old question and that it's not exactly the same case, but I was struggling with something similar, so it might be helpful to someone. In my case Batch was overwriting my ECS_DISABLE_IMAGE_CLEANUP setting, causing my special

2022-07-11 10:01:38   amazon-web-services   cluster-computing   solution   amazon-ecs

How do I specify URL resolution in python's requests library in a similar fashion to curl's --resolve flag?

Question I am writing some python client code and, due to some environmental constraints, I want to specify a URL and also control how it is resolved. I can accomplish this with curl by using the --resolve flag. Is there a way to do something similar with Python's requests library? Ideally this would work in Python 2.7 but I can make a 3.x solution work as well. Answer1 After doing a bit of digging, I (unsurprisingly) found that Requests resolves hostnames by asking Python to do it (which is asking your operating system to do it). First I found some sample code to hijack DNS resolution (Tell

2022-07-11 10:01:34   python   python-requests

How to render edges as cylinders?

Question I've loaded an OBJ polyhedron and I've used EdgesGeometry() to extract its edges: var edges = new THREE.LineSegments(new THREE.EdgesGeometry(child.geometry), new THREE.LineBasicMaterial( {color: 0x000000}) ); But I would like to render each edge as a cylinder with configurable radius. Something like this: Answer1 A customizable solutuion, which you can start from: var edgesGeom = new THREE.EdgesGeometry(dodecahedronGeom); //EdgesGeometry is a BufferGeometry var thickness = 0.25; // radius of a cylinder for (var i = 0; i < edgesGeom.attributes.position.count - 1; i+=2){ // when you

2022-07-11 10:01:30   three.js   rendering   edges

Removing ggplot2's geom_point icons from the legend

Question Note: This is a follow-up to this question. First the code to reproduce the data: mydf <- data.frame(year = c(rep(2000, 3), rep(2002, 3), rep(2004, 3), rep(2006, 3), rep(2008, 3), rep(2010, 3), rep(2012, 3), rep(2014, 3), rep(2016, 3)), answer = rep(c("A great deal", "Hardly any", "Only some"), 9), result = c(0.3015940, 0.1399303, 0.5584757, 0.2269548, 0.1792754, 0.5937698, 0.2955301, 0.1309859, 0.5734840, 0.3008197, 0.1344499, 0.5647303, 0.1919454, 0.2026290, 0.6054256, 0.1059793, 0.4190533, 0.4749674, 0.1190636, 0.3631279, 0.5178085, 0.1518314, 0.3181203, 0.5300483, 0.1424715, 0

2022-07-11 10:01:23   r   ggplot2

Cmake override find_package for a given target

Question We have a CMakeLists.txt that links (for instance) opencv to our various binaries. This is done as follow: find_package(OpenCV REQUIRED core imgproc highgui contrib) target_link_library(XXX opencv_core) We also would like to allow the person building the library to provide its own opencv library. It seems that this could be done setting -DCMAKE_PREFIX_PATH to the right path. cmake -DCMAKE_PREFIX_PATH=".../mybuild/include;.../mybuild/lib" . However I would like to be sure the library used is exactly the one specified by the client (i.e. if there is nothing in /mybuild/lib the

2022-07-11 10:01:20   cmake

In for each loop i want to skip ", " in last iteration

Question I want to skip printing ", " in last iteration. I want output like name, name, name Output now i am getting is name, name, name, StringBuffer stringBuffer = new StringBuffer(); for(MovieModel.Cast cast : movieModelList.get(position).getCastList()){ stringBuffer.append(cast.getName() + ", "); } Answer1 You can append the comma before you append the name. Like this: StringBuffer stringBuffer = new StringBuffer(); for(MovieModel.Cast cast : movieModelList.get(position).getCastList()){ if (stringBuffer.length() != 0) { stringBuffer.append(","); } stringBuffer.append(cast.getName()); }

2022-07-11 10:01:16   java   android   arrays   android-layout

Check key exist in python dict

Question Below is the file output: apples:20 orange:100 Below is the code: d = {} with open('test1.txt') as f: for line in f: if ":" not in line: continue key, value = line.strip().split(":", 1) d[key] = value for k, v in d.iteritems(): if k == 'apples': v = v.strip() if v == 20: print "Apples are equal to 20" else: print "Apples may have greater than or less than 20" if k == 'orrange': v = v.strip() if v == 20: print "orange are equal to 100" else: print "orange may have greater than or less than 100" In above code i am written "if k == 'orrange':", but its actually "orange" as per output

2022-07-11 10:01:12   python   python-2.7