Posts

ruby on rails - jQuery character count onkeyup showing 1 character when 0 left -

i'm using jquery show characters remaining in text input , it's working fine when gets 0 characters remaining showing 1 though doesn't allow enter more. obvious , simple, it's stumping me today. here code i'm using: = form.text_field :name, { required: true, class: "#{'error' if @project.errors[:name].present?}", placeholder: '40 characters max', maxlength: 40, :onkeyup => "countcharname(this)" } span id="charname" class="margin-left-5" function countcharname(val) { var len = val.value.length; if (len >= 40) { val.value = val.value.substring(0, 40); } else { $('#charname').text(40 - len); } }; without testing it, assumption when reaches max length, input length 40. means if statement (len >= 40) true, else statement, updates $('#charname') remaining characters, doesn't run. try changing if statement (l...

geospatial - How can I query a MongoDB collection by both a geo spatial index and a text index quickly? -

given collection locations consisting of ~20,000,000 documents 3 properties: { _id, name, // string geo // coordinate pair, e.g. [-90.123456, 30.123456] } and index of name: 1 , geo index setup so: { "geo" : "2dsphere" }, { "v" : 1, "name" : "geo_2dsphere", "ns" : "db.locations", "min" : "-180.0", "max" : "180.0", "w" : 1.0, "2dsphereindexversion" : 2 } how can performantly query against collection both on geo_2dsphere index , on name index? when run $box query on geo index only, takes on 20 seconds return 50 results. when include search against name property goes further. if run $near query, things can perform quickly, queries seem (very randomly) go ~200ms many seconds. see example difference 1 additional character on name index increases time: 200ms: {name: /^mac/, geo: {$near...

javascript - Order function call -

i need make submitadapterauthentication() function work first getuserroles() function, current implementation of getuserroles() function being executed first submitadapterauthentication() . how can fix this? checkonline().then(function(onl) { userobj.isloginonline = onl; }).then(function() { submitadapterauthentication(user, pass); }).then(function() { getuserroles(); }); function submitadapterauthentication(user, pass) { var invocationdata = { parameters : [ user, pass ], adapter : "adapterauth", procedure : "submitlogin" }; ch.submitadapterauthentication(invocationdata, { onfailure : function(error) { wl.logger.log("error on fail: ", error); }, onsuccess : function() { wl.client.updateuserinfo({ onsuccess : function() { //return promise wl.client.updateuserinfo({ ...

python - I have five variables that will have different values based on whether they are in Alaska/US and at half/full resolution -

question appropriate data structure: i have 5 variables have different values string based on whether in us/alaska , @ half/full resolution. so i'm building 5/2/2 (array or list or dict). i want access x = dstr(var,'ak','h') , e.g.. alaska/half-res, values osp/ul/lr/etc, variables? this static table, values won't change. there no obvious ordering demand 0,1,2 indices problem is, array doesn't string indices , dict wants 1 key only, not three. any ideas? you can use tuples index dict: >>> values = { ... ("ak", "h"): ("some", "sample", "data", "to", "return"), ... ("ak", "f"): ("more", "sample", "data", "for", "you"), ... # more data here ... } >>> a, b, c, d, e = values[("ak", "h")] >>> "some" or can use nest of dicts: ...

sql - i have a error in joomla - query please. i have and error in this query -

$datos = explode(';',$linea); $product_ean = trim($datos[0]); $product_price = trim($datos[1]); $name_es = trim($datos[2]); $short_description_es = trim($datos[3]); echo $product_ean,'<br>'; echo $product_price,'<br>'; echo $name_es ,'<br>'; echo $short_description_es,'<br>'; $db = jfactory::getdbo(); $query = $db->getquery(true); $columns = array('product_id' ,'product_ean', 'product_price', 'name_es-es', 'short_description_es-es'); $values = array(null, $product_ean, $product_price, $name_es, $short_description_es); $query ->insert($db->quotename('vrg_jshopping_products')) ->columns($db->quotename($columns)) ->values(implode(',', $values)); $db->setquery($query); $db->execute(); error displaying error page: application instantiation error: have e...

node.js - KoaJS how to get files from multipart form data? -

when post multipart form, <form name="acount_manage" action="/update" enctype="multipart/form-data" method="post"> <input type="file" name="file"> </form> it throws: error: unsupported content-type: multipart/form-data @ object.<anonymous> (e:\...\node_modules\co-body\lib\any.js:51:15) any.js: /** * module dependencies. */ var json = require('./json'); var form = require('./form'); var text = require('./text'); var json_content_types = [ 'application/json', 'application/json-patch+json', 'application/vnd.api+json', 'application/csp-report', 'application/ld+json' ]; /** * return a thunk parses form , json requests * depending on content-type. * * pass node request or object `.req`, * such koa context. * * @param {request} req * @param {options} [opts] * @return {functi...

mysql - Combine Two Select Statements Using UNION -

i learning sql statements, cannot see why code cannot execute database: (select time mytable) union (select travel mytable); the above statement forbidden. it not columns called time , travel of same datatype... when union 2 select statements, putting 2 values in same column. sql not know type make column. likely, sees time values, makes column datetime column, start trying cram travel varchar strings it. try casting both same type, this: select date_format(time, '%y-%m-%d %h:%i:%s') time mytable union select travel mytable;