Posts

c# - Creating multidimensional array at runtime -

i did research on web couldn't find advice how dynamically create multidimensional (rank >1) array (it jagged array). in other words program ask number of dimensions (rank) first, number of elements per dimension (rank) , create array. is possible? multidimensional no, no problem jagged - here simple example: using system; using system.collections.generic; public class program { public static void main() { list<list<list<int>>> myjaggedintlist = new list<list<list<int>>>(); myjaggedintlist.add(new list<list<int>>()); myjaggedintlist[0].add(new list<int>()); myjaggedintlist[0][0].add(3); console.writeline(myjaggedintlist[0][0][0].tostring()); } } each item in first list list , each item in second list list , , each item in third list int . what's problem that? play in fiddle.

mocking - phpunit mock method called in constructor -

i test config class, parsing config file , allows me various settings app. my goal mock parse() method of config class, called in constructor , set method returning in constructor. this way, prevents file_get_contents() being called (in parse() method) , enables me have config class config property set contain array of properties. but haven't succeeded doing that. here code: the config class: <?php namespace example; use symfony\component\yaml\parser; class config { private $parser; private $config; public function __construct(parser $parser, $filepath) { $this->parser = $parser; $this->config = $this->parse($filepath); } public function parse($filepath) { $fileasstring = file_get_contents($filepath); if (false === $fileasstring) { throw new \exception('cannot config file.'); } return $this->parser->parse($fileasstring); } public function get($path = null) { if ($path) { $config = $thi...

php - How can I connect a value of one mySQL table to a value of another table? -

i have 2 tables in mysql database: table "animals": | animal | name | |:-----------|------------:| | cat | tom | | dog | | table "orders": | id | animal | |:-----------|------------:| | 1 | cat | | 2 | dog | at first select table "orders" following data: <?php $pdo = database::connect(); $sql = 'select * orders order id asc'; foreach ($pdo->query($sql) $row) { echo ('<td>a:'.$row['id'].'</td>'); echo ('<td>b:'.$row['animal'].'</td>'); echo ('<td>c:'.$row['animal'].'</td>'); } database::disconnect(); ?> now want check if in mysql table "animal" animal has name . if yes print @ position b name . if there no name print animal : | a:1 | ...

if statement - PHP Conditionals: is_null($someVariable) vs. $someVariable === 0 -

i debugged problem had root mention down here: the first conditional true; second conditional not execute; why 2nd conditional not execute? $somevariable = 0; if ( $somevariable === 0 ) var_dump('worked'); if ( is_null($somevariable) ) var_dump('worked too'); i think saw working in 'legacy' code, not sure it. from is_null docs: returns true if var null, false otherwise. the second conditional doesn't execute because $somevariable isn't null.

android - CustomListView OnItemClickListener not working -

i used local database fetch records , create custom list view using that. custom list view gets displayed perfectly. problem onitemclicklistener. doesn't on click. aim send position of clicked item activity. implemented it's not working. screenshot of list view - https://www.dropbox.com/s/pz83i162sxdv2b0/untitled.png?dl=0 here mainactivity.java : public class mainactivity extends actionbaractivity { listview lv; textview tv1,tv2,tv3; arraylist<string> a=new arraylist<string>(); string mydata,name,name1; public string[] s1 = new string[50]; public int[] img = {r.drawable.rty, r.drawable.sf, r.drawable.rty}; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); tv1=(textview)findviewbyid(r.id.textview); lv = (listview) findviewbyid(r.id.listview); new mydata().execute(); lv.setonitemclicklistener(new adapterview.onitemclicklistener() { @o...

Will a C compiled .so work with a C++ application? -

if want dynamically link shared library (.so) c++ application (which built g++) using ld_preload, matter if .so generated c source file (using gcc) or c++ source file (using g++)? , why or why not? thanks helping me understand this. yes, c++ executable can linked (both statically , dynamically) c library. this deliberate. c++ abis designed backwards compatible. you have ensure declarations of functions , on of library symbols, written in c++ program, marked extern "c" denote crossing language boundary. typically, library's own shipped header files you.

c - Segmentation Fault, large arrays -

#include <stdio.h> #define n 1024 int main(){ int i, j; int a[n][n]; int b[n][n]; (i=0;i<n;i++){ a[i][i]=i; b[i][i]=i; } (i=0;i<n;i++) for(j=0;j<n;j++) { printf("%d", a[i][j]); printf("%d", b[i][j]); } return 0; } this program reason of segmentation fault, if define n 1023, program work correctly. why happens? you overflowing stack. 2 * 1024 * 1024 * sizeof(int) lot systems. the simplest solution make arrays static . static int a[n][n]; static int b[n][n]; other methods: make arrays global (this same above) use malloc in loop , of course remember free int **a = malloc(n * sizeof *a); (i = 0; < n; i++) a[i] = malloc(n * sizeof *a[i]);