Posts

node.js - Generic JavaScript Models using Composition -

i working on node.js application couple of javascript model this: function role(data) { this.data = data; ... } role.prototype.save = function(...) {...} role.findbyid = function(...) {...} role.findall = function(...) {...} all of them using same (similar) logic of functions, need different implementation saving , on. idea refactor them using kind of composition. current solution combination of using inheritance prototype functions , adapter static functions. looks this. var _adapter = new databaseadapter(schema, table, role); function role(data) { model.call(this, _adapter, role._attributes) this.data = data; ... } role._attributes = { name: '' } role.prototype.save = function(...) {...} role.findbyid = function(...) { _adapter.findbyid(...); } role.findall = function(...) { _adapter.findall(...) } but, not happy current solution, because developers need know lot of implementation details create new model. so, hope show me better approach so...

php - sending values from controller to views -

how can achieve this, sending data view controller form in view, need pick data on table in database , sending controller view, here controller: public function new_orders(){ //data views form in views $category_id=$this->uri->segment(3); $data['registration_number'] = $category_id; //data model view $this->data["product_id"]=$this->select->get_product_id(); $this->load->view("product_add", $data); } my model: function get_product_id(){ $this->db->select_max('product_id'); $this->db->from('products'); $query = $this->db->get(); return $query->result_array(); } i want form in view display registration_number @ same time product_id. in view registration_number displayed not product_id, seems undefined variable. me please solve it update code below, use $this->data instead of $data $this->load->view("product_add", $this->data...

Add one more element to multi dimensional array in java -

a method returning 2-dimensional array in java. want add 1 more element it. not sure of syntax of how copy new 2-d array& add 1 more element. have idea? string arr[][]=gettwodarray(); now want add 1 more row it. this string newarr[][] = new string[arr.length+1][]; arr[length+1][0]= {"car"}; any idea? you can't resize arrays: size fixed @ creation time. you can create new array , copy contents in; can conveniently using arrays.copyof (*): string newarr[][] = arrays.copyof(arr, arr.length + 1); // note newarr[arr.length] null. newarr[arr.length] = new string[] { "car" }; however, pointed out @kevinesche in comment on question, might find arraylist (or maybe other kind of list ) more convenient use: although backed array, , needs resize array occasionally, hides details you. (*) gotcha here arrays.copyof performs shallow copy of arr , changes elements of arr[i] reflected in elements of newarr[i] (for 0 <= < arr.length ...

Easiest way to deploy docker application -

my application uses multiple technologies redis, couchdb, nodejs, ... of them take docker hub (e.g. redis) , others (e.g. nodejs app) hosted in docker repo on own server. easiest way deploy full application remote system? great if use 1 docker-compose.yml , run docker-compsoe -d , think won't work, because use images own docker repo. first have pull these images via docker pull on remote system or possible tell .yml-file pull repo? or there other solution? don't worry private registry. docker-compose can pull images private repository automatically. you need authenticate before on private resgistry before pulling. type $docker login <private_repository> before $docker-compose up note! there need give right names own images. need tag image your_registry_host docker tag [options] image[:tag] [registryhost/][username/]name[:tag] and after can push image own registry. docker-compose need specify full image name hostname image: my_registry/image_nam...

php - Can't use two ore more filters with Elasticsearch -

i'm using elasticsearch in project. elasticsearch query that: array( [index] => galaxy [type] => galaxy [size] => 1000 [from] => 0 [body] => array( [query] => array( [filtered] => array( [query] => array( [query_string] => array( [default_operator] => , [query] => vestel* ) ) [filter] => array( [bool] => array( [must] => array( [term] => array( [fk_product_category] => 1 [fk_product_group] => 1 ) ) ) ) ) ) ) ) when remove 1 of filters terms example fk_product_group works when use both filters fatal error co...

c++ - std::cout with multi changing variables -

assuming code int main(){ int i=0, j=0; cout << << " " << f1(&i,&j) << " " << j << endl; cout << << " " << j << endl; } int f1(int *i, int *j){ *i = 20; *j = 30; return 10; } the result is 20 10 0 20 30 i puzzled why j 0 while correctly shows 20 edit: have read on sequence point still unsure of how explain this. should assume j evaluated first before f1 evaluated hence j 0 , 20? here thing: cout << << " " << f1(&i,&j) << " " << j << endl; if consider right left evaluation, j 0 , printed. then, f1 called , j value changed 30 . order of evaluation unpredictable

I couldn't get the current userid using get_currentuserinfo() in Wordpress -

i new in wordpress, created wordpress api using wp rest api . created custom route in api in callback didn't current user id , user details using function get_currentuserinfo() in wordpress 4.5 function get_currentuserinfo() has been deprecated replace get_currentuserinfo() with wp_get_current_user(); deprecated info found here : https://developer.wordpress.org/reference/functions/get_currentuserinfo/ have try this. current user information .