MVC: Validation in model, as separate function or within the called function?

Uncategorized
Question: There are many helpful questions and great answers related to "Where to place validation: controller or model?":Best Place for Validation in Model/View/Controller Model? MVC Question: Should I put form validation rules in the controller or model? Where to validate data Controller or Model in CodeIgniter MVC: Does the Model or Controller validate user input If I placed validation in the model, should the validation be in a separate function or within the same called function? Like:// This is a model file, with 1 function "insert()" public function insert() { // Validate before insert ... // If validation passed, then insert into db ... } OR like this:// This is a model file, with 2 functions "insert()" and "validateInsert()" public function insert() { // Validate before insert validateInsert(); // If…
Read More

javascript selectpicker doesn’t work

Uncategorized
Question: I'm using bootstrap-sass and i want to use selectpicker for search but it doesn't work !! this is my application.js //= require rails-ujs //= require turbolinks //= require jquery3 //= require jquery_ujs //= require jquery.min.js //= require bootstrap.min.js //= require bootstrap-datepicker //= require_tree . this is my application.js *= require_tree . *= require_self *= require bootstrap-datepicker3 */ @import "bootstrap-sprockets"; @import "bootstrap"; and this is my view Bootstrap-select example Tom Foolery Bill Gordon Elizabeth Warren Mario Flores Don Young Marvin Martinez Answer: Here you have a working example. I thing your probleme come from js/css import. $('.selectpicker').selectpicker({ style: 'btn-info', size: 4 }); Bootstrap-select example Tom Foolery Bill Gordon Elizabeth Warren Mario Flores Don Young Marvin Martinez Run code snippetHide results Expand snippet Read more
Read More

How to send both data and header to a server?

Uncategorized
Question: I want to send a header to a server using http call POST request. When I send the header only, everything is ok. but when I add some data to the call, I get an error:http://localhost:3000/test_post. Request header field Content-Type is not allowed by Access-Control-Allow-Headers in preflight response. I use node.js as the server side language, this is the code for the CORS settings:app.use(function(req, res, next) { res.header("Access-Control-Allow-Origin", "*"); res.header("Access-Control-Expose-Headers", "x-auth"); res.header("Access-Control-Allow-Headers", "x-auth"); next(); }); This is the $http call with angular:$http({ method: 'POST', data: {name: 'Dani'}, url: 'http://localhost:3000/test_post' headers: { 'x-auth': 'some token' } }).then(function successCallback(response) { console.log(response.data); }, function errorCallback(response) { console.log('error'); }); I know problem is about the CORS, but I don't know what to modify there, If I remove res.header("Access-Control-Allow-Headers", "x-auth"); from the CORS I…
Read More

How to correct pagination in oracle?

Uncategorized
Question: I am showing user record of how many forms he/she has accepted and for that purpose I am using pagination in php. Data is fetched from oracle database and shown in the table. I am using pagination, but when I go on next page it shows the previous record's new records are not shown. Answer: This is explained in the The Underground PHP and Oracle Manual, page 181: The canonical paging query for Oracle8i onwards is given on http://asktom.oracle.com:select * from ( select a.*, rownum as rnum from (YOUR_QUERY_GOES_HERE -- including the order by) a where rownum = MIN_ROW Here, MIN_ROW is the row number of first row and MAX_ROW is the row number of the last row to return. There is even a full example script: Read more
Read More

Fix precision issues when *displaying* floats in python

Uncategorized
Question: I'm reading out a text file with some float numbers using np.loadtxt . This is what my numpy array looks like:x = np.loadtxt(t2) print(x) array([[ 1.00000000e+00, 6.61560000e-13], [ 2.00000000e+00, 3.05350000e-13], [ 3.00000000e+00, 6.22240000e-13], [ 4.00000000e+00, 3.08850000e-13], [ 5.00000000e+00, 1.11170000e-10], [ 6.00000000e+00, 3.82440000e-11], [ 7.00000000e+00, 5.39160000e-11], [ 8.00000000e+00, 1.75910000e-11], [ 9.00000000e+00, 2.27330000e-10]]) I separate out the first column from the second by doing this:idx, coeffs = zip(*x) Now, I want to create a mapping of id : coeff, something like this:mapping = dict(zip(map(int, idx), coeffs)) print(mapping) {1: 6.6155999999999996e-13, 2: 3.0535000000000001e-13, 3: 6.2223999999999998e-13, 4: 3.0884999999999999e-13, 5: 1.1117e-10, 6: 3.8243999999999997e-11, 7: 5.3915999999999998e-11, 8: 1.7591e-11, 9: 2.2733e-10} As you can see, precision errors have been introduced. For example, 6.61560000e-13 became 6.6155999999999996e-13. This is what I would like, preferrably:{1: 6.61560000e-13, 2: 3.05350000e-13, 3: 6.22240000e-13,…
Read More

Use Module.HEAP8.set Get messed data

Uncategorized
Question: I use emscripten compile the c code into asm.js my c code like this:int _call_main(char* p, int number)//p is the start arrary, number is the lengh I want to send a bytearray data to the c code, My Js code like this:var decode_encode_audio = Module.cwrap('_call_main', 'number', ['array','number']); ........ var byteArray = new Uint8Array(message.data);//audio data var offset = Module._malloc(70000); Module.HEAP8.set(byteArray, offset); decode_encode_audio(offset , byteArray.length); In the C code, I print the point p array, I got a messed data, the start part and the end part of p is correct(I save the file), However, In the middle part is messed.I replace the function(Module.HEAP8.set) with [Module.HEAPU8.set],also got error. I don't know why? I change the Js code :var decode_encode_audio = Module.cwrap('_call_main', 'number', ['number','number']);//not array ........ var byteArray = new Uint8Array(message.data);//audio data…
Read More

In C# How to call Set method without a value

Uncategorized
Question: I have a property and a set method that do something, I want to call that set method but without a value, How can I do that? For example for the following property with set method:private int myNum; public String MyNumber { get { return myNum }; set { Randon rnd = new Random(); myNum = rnd.Next(1,13); } } Answer: Not possible and a strange idea. Provide a method if you need "to do something":private int myNum; Random rnd = new Random(); public int MyNumber { get { return myNum; } } public void GenerateMyNumber(int minInclusive, int maxExclusive) { myNum = rnd.Next(minInclusive, maxExclusive); } Note that i have made the Random variable a field in the class, otherwise the method generates always the same number if called very fast(f.e.…
Read More

GDB: ImportError: No module named libstdcxx.v6.printers

Uncategorized
Question: I have MSYS2 and MinGW64 installed under Windows 7. gdb reports "ImportError: No module named libstdcxx.v6.printers":$ gdb GNU gdb (GDB) 7.11.1 Copyright (C) 2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-pc-msys". Type "show configuration" for configuration details. For bug reporting instructions, please see: . Find the GDB manual and other documentation resources online at: . For help, type "help". Type "apropos word" to search for commands related to "word". Traceback (most recent call last): File "", line 3, in ImportError: No module named libstdcxx.v6.printers /etc/gdbinit:6: Error in sourced…
Read More

Join table more than one id from the joined table

Uncategorized
Question: i have tables like this Employee id | employee | 1 | gorg | 2 | ocle | 3 | oke | Task id | employeeId1 | employeeId2 1 | 1 | 1 2 | 3 | 2 Query SELECT a.employeeId1, b.employee as employee1, a.employeeId2, c.employee as employee2, FROM `Task` a LEFT OUTER JOIN Employee b on a.employeeId1 = b.id LEFT OUTER JOIN Employee c on a.employeeId2 = c.id Result id | employeeId1 | employee1 | employeeId2 | employee2 1 | 1 | gorg | 1 | gorg 2 | 3 | oke | 2 | ocle In my query, i have to join Employee table with Task to get Employee's name. In the the first join, i joined with Employee Table to get Employee name for employeeId1, but…
Read More

nginx: support user-defined encryption method

Uncategorized
Question: I'm new to nginx, as far as I know, nginx has ngx_http_ssl_module to do https. But I got a problem that the received tcp packet is encrypted in user defined encryption method and can't use ngx_http_ssl_module. The decrypted content is http packet, so it can be handled by normal http module later on. What I have done is to modify the source code in ngx_recv.c, n=recv(c->fd,buf,size,0);//we can decrypt the buf here It can solve the problem but I don't want to modify the source code, what I really want is to add a custom nginx module to do it. It seems that ngx http core module will handle the tcp event internally, but I want add my own handler to decrypt the tcp packet. In the source code, it…
Read More

Medica – Medical HTML Template

Uncategorized
Medica – Medical HTML Template is powerful and eye-catching HTML Template. It is fully responsive, well structured and beautiful HTML template which is specifically designed for for hospital,psychology, clinic, doctor, dentist, surgeon, gynecologist, drugstores, health-care, pharmacies, medical labs and other medical related organizations. This template is very easy to customize.
Read More

Typescript – how to use utilities file project-wide with minimum ceremony?

Uncategorized
Question: I've been working with Typescipt for a few months, and this aspect has been annoying me over the course of several projects already. Suppose I have the following project structure:project +- app | +- component1 | | +- component1.ts | +- component2 | | +- component2.ts | +- utils | +- utils.ts +- tsconfig.json Now, suppose that utils.ts file contains a lot of helper classes (e.g. data structures) and maybe even global functions, and almost every other file in project uses at least some part of it. How would you use it with a minimum amount of boilerplate code? Using import statement // utils.ts export function foo() { return 1; } // component1.ts import { foo, bar, baz, ...(a long list here) } from '../utils/utils' let x = foo();…
Read More

Button For Adding New data validation (Add new my default workbook in macro excel)

Uncategorized
Question: I want to make data validation entry with VBA excel that contain a lot of rules of validation. I want to make “add new validation entry button”. If I click the button, it will automatically make a new workbook. This is what i try last night: For the first time, I perepare 2 file of xlsm in my D: folder (the files have the same contain). One file for making validation entry for the first time which contain “add new validation entry button”. The other one is xlsm file before input the data validation which contain “add new validation entry button” too (name of the file is (original workbook). If i click it, it will automatically copy the “original workbook”, close the current program, and give me a new…
Read More