Wednesday, 7 August 2013

cast string to array php

cast string to array php

I have a PHP array, but when I var_dump($array) it returns it as a string.
array(1) {
[0]=>
string(1874) "array(
I tried to do var_dump( (array) $array), but that returns the same array
as a string again, except this string is now in a single array value.
Any idea on how I can turn this "array" into an actual array?
Thanks!

Another "Comparison method violates its general contract!"

Another "Comparison method violates its general contract!"

I'm being asked to investigate a bug as part of my internship. A piece of
code is throwing java.lang.IllegalArgumentException: Comparison method
violates its general contract! A custom Comparator is comparing two custom
classes by looking at long member variables of said custom class return v1
> v2 ? -1 : v1 < v2 ? 1 : 0; The equals method for this custom class looks
at a String member variable of this custom class. We're having a hell of a
time reproducing the behavior. My knee-jerk reaction was to replace the
return statement in the custom Comparator with return v2.compareTo(v1);,
but my team is skeptical that this will address the problem. Can anyone
offer any insight?

Extracting SVG from Font Awesome

Extracting SVG from Font Awesome

I want to get the SVG path data from Font Awesome glyphs so that I can use
them straight up as SVG in my HTML. I thought it would be as easy as
copy-pasting the path data from fontawesome-webfont.svg, but when I use it
in my HTML the symbols are all rendering upside-down. Anyone know why?
(See Fiddle)
Font Awesome SVG:
<glyph unicode="&#xf007;" horiz-adv-x="1408" d="M1408 131q0 -120 -73
-189.5t-194 -69.5h-874q-121 0 -194 69.5t-73 189.5q0 53 3.5 103.5t14
109t26.5 108.5t43 97.5t62 81t85.5 53.5t111.5 20q9 0 42 -21.5t74.5 -48t108
-48t133.5 -21.5t133.5 21.5t108 48t74.5 48t42 21.5q61 0 111.5 -20t85.5
-53.5t62 -81 t43 -97.5t26.5 -108.5t14 -109t3.5 -103.5zM1088 1024q0 -159
-112.5 -271.5t-271.5 -112.5t-271.5 112.5t-112.5 271.5t112.5 271.5t271.5
112.5t271.5 -112.5t112.5 -271.5z" />
... Ported to HTML SVG (and scaled down):
<svg width="1000" height="1000" ><path transform="scale(0.1,0.1)" d="M1408
131q0 -120 -73 -189.5t-194 -69.5h-874q-121 0 -194 69.5t-73 189.5q0 53 3.5
103.5t14 109t26.5 108.5t43 97.5t62 81t85.5 53.5t111.5 20q9 0 42 -21.5t74.5
-48t108 -48t133.5 -21.5t133.5 21.5t108 48t74.5 48t42 21.5q61 0 111.5
-20t85.5 -53.5t62 -81 t43 -97.5t26.5 -108.5t14 -109t3.5 -103.5zM1088
1024q0 -159 -112.5 -271.5t-271.5 -112.5t-271.5 112.5t-112.5 271.5t112.5
271.5t271.5 112.5t271.5 -112.5t112.5 -271.5z"/></svg>

12 side dice. Roll to first odd cumulative sum. What is the most likely odd number to appear?

12 side dice. Roll to first odd cumulative sum. What is the most likely
odd number to appear?

Given a 12 sided dice, you roll the dice repeatedly until the cumulative
sum is odd. What is the number of the cumulative sum you can have with the
highest probability?

Directory index forbidden by Options directive error in Cakephp

Directory index forbidden by Options directive error in Cakephp

Getting Directory index forbidden by Options directive error when trying
to upload images but not getting that every time, so not know the exact
senario, i have check the error_logs of apache. The .htaccess in webroot
is
`<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>`
I fixed this using +Indexes in < Directory > but i don't know why i'm
getting the error so some images only they are of ~700 KB and ~1500 X 1700
in size.

testng data provider parameter in setUpMethod

testng data provider parameter in setUpMethod

I have some init statemnts that need to be done with the data provider
parameter and would want to access the data provider parameter value in
the @BeforeMethod setup method. Is this possible?

matrix region sum function

matrix region sum function

I'm having trouble understanding this piece of code. This function
determines the sum of a selected area in a matrix. You are given matrix
and coordinates of the top left(A) and bottom right(D) corner of the
rectangle.
def matrixRegionSum(matrix, A, D):
if len(matrix) == 0:
return
totalSum = 0
for i in range(A[0], D[0] + 1):
for j in range (A[1], D[1] + 1):
totalSum += matrix[i][j]
return totalSum
The part I am stuck on is inside the range() function. I'm not sure how
A[0], B[0], A[1], and B[1] access the matrix. Could someone explain? I see
A[0] as the first value in an array, but a matrix is 2D. Could someone
explain to me the logic behind this function?
Thank you for the help! much appreciated!