[Solved] panic: runtime error: index out of range 1

finally i figure this out XD! type obj struct { Targets []string `json:”targets”` Labels map[string]string `json:”labels”` } func main() { // Creating simulation var myobj = []*obj{} n := new(obj) n.Targets = append(n.Targets, “10.0.0.1”) n.Labels = make(map[string]string) n.Labels[“job”] = “db2” myobj = append(myobj, n) k := new(obj) k.Targets = append(k.Targets, “192.168.1.12”) k.Targets = append(k.Targets, “192.168.1.13”) … Read more

[Solved] Present a viewcontroller in UIView [closed]

To add a view controller to another view controller, you can do the following: Inside the parent view controller class: addChildViewController(someViewController) view.addSubview(someViewController.view) someViewController.didMove(toParentViewController: self) someViewController.view.translatesAutoresizingMaskIntoConstraints = false Then, set the layout constraints to position the view controller: NSLayoutConstraint.activate([ someViewController.view.leadingAnchor .constraint(equalTo: view.leadingAnchor ), someViewController.view.trailingAnchor.constraint(equalTo: view.trailingAnchor), someViewController.view.bottomAnchor .constraint(equalTo: view.bottomAnchor ), someViewController.view.topAnchor .constraint(equalTo: view.topAnchor ) ]) view.layoutIfNeeded() 2 … Read more

[Solved] I want regular expression (theory of automata)

Going completely classic regular expression (i.e. disjunction, concatenation, and kleene star): (799|(8|9)(0|1|2|3|4|5|6|7|8|9)(0|1|2|3|4|5|6|7|8|9)(0|1|2|3|4|5|6|7|8|9)*|(1|2|3|4|5|6|7|8|9)(0|1|2|3|4|5|6|7|8|9)(0|1|2|3|4|5|6|7|8|9)(0|1|2|3|4|5|6|7|8|9)(0|1|2|3|4|5|6|7|8|9)*) If you allow typical regex shorthands (but stay within the theoretical limits, i.e. a regular language), that can be reduced to: 799|[89]\d{2,}|[1-9]\d{3,} You match either the number 799, a three digit number starting with 8 or 9, or a four- (or more) -digit … Read more

[Solved] Using JSON Decodable in Swift 4.1

Your previous question is quite close but you have to add the struct for the root object Declare the struct members non-optional as much as possible. The URLs can be decoded as URL struct Root : Decodable { let count : Int let recipes : [Recipe] } struct Recipe : Decodable { // It’s highly … Read more

[Solved] How to read a file line by line in PHP

I assume you need a way to make it more dynamic than manually typing [0] then [1] and so on? You can loop the txtfile with foreach and assign new array items with []. $file = fopen(“path of txt”); foreach($file as $line){ $numDoc[] = substr($line, 46, 5); $dateDoc[] = substr($line, 30, 8); } The code … Read more

[Solved] Pseudo code to C++ code [closed]

Can this be done better using standard library functions? Hell yes. At the very least, temp = RandomizeArray[i]; RandomizeArray[i] = RandomizeArray[j]; RandomizeArray[j] = temp; Is all replaced by std::swap(RandomizeArray[i], RandomizeArray[j]); The whole process is sort-of replaced (but not quite. Almost certainly a different backing algorithm) by the std::random_shuffle family, but that would be totally defeating … Read more

[Solved] How to get all seperate all equal pairs from a list in python

print [a for a,b in zip(my_list[::2],my_list[1::2]) if a == b] you may need to sort my_list first … my_list = sorted(my_list) print [a for a,b in zip(my_list[::2],my_list[1::2]) if a == b] Im not at all sure this solves your issue. def do_this_weird_thing(a_list): from itertools import groupby for grp,item in groupby(sorted(a_list)): item = list(item) yield [grp] … Read more

[Solved] What is the best way to organize a lot of data which contains multiple conditions?

You could organize your data as follows: class Program { static void Main(string[] args) { List<Criteria> list = new List<Criteria>() { new Criteria(Color.green, Country.england, Town.london, GoodBad.good, DayOfTheWeek.sunday, Daytime.evening), new Criteria(Color.red, Country.thenetherlands, Town.amsterdam, GoodBad.bad, DayOfTheWeek.monday, Daytime.night), new Criteria(Color.blue, Country.america, Town.newyork, GoodBad.bad, DayOfTheWeek.tuesday, Daytime.morning), }; Console.WriteLine(“- Native sorting:”); list.Sort(); foreach(var criteria in list) { Console.WriteLine(criteria); } Console.WriteLine(); … Read more

[Solved] Equivalent of and in JavaScript?

A googling for “javascript AND operator” returns a first hit of http://www.w3schools.com/js/js_comparisons.asp which clearly explains the answer: if (i % 3 && 5 === 0) This is the answer you’re looking for, but given how it’s written, it might not give you the outcome you expect depending on execution. 5 solved Equivalent of and in … Read more

[Solved] How to stop the thread in android activity [duplicate]

In onStop() method, call interrupt as follows: yourThreadObject.interrupt() and in the run() method of the thread, have a condition that checks for Thread’s interrupt status. Depending on your implementation, you might want to enclose this check within a while loop as, public void run() { while (!Thread.interrupted()) { //do something … } } or you … Read more

[Solved] Just using mysql real escape string [closed]

it is not working … the strings like />., still can be enter in the sql database It is working. mysql_real_escape_string is a function that escapes characters which have special meaning in SQL. / and > do not have special meaning in SQL, so it shouldn’t touch them. If they did have special meaning, then … Read more

[Solved] imagepng() expects parameter 1 to be resource [closed]

Read the manual! You have to first obtain an image resource, returned by one of the image creation functions, such as imagecreatefrompng(): $file = $PNG_WEB_DIR.basename($filename); $img = imagecreatefrompng($file); // … ob_start(“output_handler”); imagepng($img,NULL,9); $image_data = ob_get_contents(); ob_end_flush(); 4 solved imagepng() expects parameter 1 to be resource [closed]