Quantcast
Channel: User Ja͢ck - Stack Overflow
Browsing latest articles
Browse All 39 View Live

Comment by Ja͢ck on How do I add a foreach inside another foreach in this...

if you didn't reduce the code, it would look like that, yes ... the $return = (array)$return is only necessary in the shortened version; it turns $return into an array with one element if it's not an...

View Article


Comment by Ja͢ck on php number format in table

what does $item[stok_toplam] give you, and what do you need? also, you should use quotes around stok_toplam, because otherwise php thinks that you're trying to reference a constant.

View Article

Comment by Ja͢ck on Ruby class accessing protected method of child class?

@max that's an advanced topic :)

View Article

Comment by Ja͢ck on Wrap segments of HTML with divs (and generate table of...

@RobertAndrews Oh, it's just an example; the $a->setAttribute('href', '#') is where you'd want to make changes; that, and each section would need the anchor.

View Article

Comment by Ja͢ck on How to insert a decimal point before the last 2 digits of...

@mickmackusa that's fair .. i've updated my answer to make it a variable assignment instead.

View Article


Comment by Ja͢ck on How do I get the second largest element from an array in...

@JayanthKumarT well, technically the second biggest number is indeed -Infinity :)

View Article

Comment by Ja͢ck on Ruby Enumerator-based lazy flatten method

For identity function, you can use &:itself :)

View Article

Comment by Ja͢ck on Remove duplicate elements from array in Ruby

it should also be mentioned that a block can be given if the uniqueness constraint is more complex; for instance, you could do array.uniq { |i| i % 3 } to get the unique values modulo 3 (1, 2, 6)

View Article


Comment by Ja͢ck on Add property to stdClass at the top of the object in php

@5Diraptor then perhaps your $x isn't a regular array?

View Article


Comment by Ja͢ck on Ruby hash: return the first key value under which is not nil

@Ilya 5y later, but it should probably be mentioned that the answer was fixed to better reflect the question :)

View Article

Comment by Ja͢ck on How to merge array and preserve keys?

@JavierS yeah, that's why i inverted the order in that example vs the first :)

View Article

Comment by Ja͢ck on PHP: How do I print out debugging information without...

No, you'd have to do \Debug\print_r(...) or import it

View Article

Comment by Ja͢ck on How to use range() when you want number with 2 digits...

@ssuhat it means that the variable is passed by reference instead of by value, so the assignment changes the variable in-place

View Article


Answer by Ja͢ck for Create Array reference with element index instead of...

Primitive values, such as numbers, booleans, and strings are copied by value, because they're immutable; conversely, objects, arrays, and functions are copied by reference.See also: PrimitiveThis can...

View Article

Answer by Ja͢ck for What is this operator in MySQL?

TL;DRIt's the NULL safe equal operator.Like the regular = operator, two values are compared and the result is either 0 (not equal) or 1 (equal); in other words: 'a'<=> 'b' yields 0 and...

View Article


Answer by Ja͢ck for Ruby - epoch time with milliseconds to local time string

Instead of doing an explicit division by 1000, you could also consider using the :millisecond option of Time.at()> Time.at(0, 1475001600029, :millisecond)2016-09-27 18:40:00 +0000

View Article

Answer by Ja͢ck for xpath to exclude elements that have a class

You can use negation://*[@id="mydiv" and @class!="exclass"]If the class attribute may not exist on all nodes, you need this://*[@id="mydiv" and (not(@class) or @class!="exclass")]The last (somewhat)...

View Article


Answer by Ja͢ck for How can I get the class of a parent element?

Your code should already work, but it might be more reliable to access the property className instead:jQuery(function($) { console.log($('.nav a.current').parent().prop('className'));});<script...

View Article

Answer by Ja͢ck for PHP - 8 decimals don't work

You can set the precision used when formatting floats as strings using the precision ini setting, the default being 14:ini_set('precision', 16);echo $a - $b; // 1999999.99999999Also, read this article...

View Article

Answer by Ja͢ck for Will flock'ed file be unlocked when the process die...

According to the manual page of flock() that PHP uses internally, a lock is released when either flock() is called with LOCK_UN or when the descriptor is closed using fclose().Upon script termination,...

View Article

Answer by Ja͢ck for PHP Overriding methods rules

The rule is that a method signature must be compatible with the method it overrides. Let's look at the two methods in your hierarchy:protected function playing($game = 'ball');public function...

View Article


Answer by Ja͢ck for ruby: how to find non-unique elements in array and print...

From Ruby 2.7, you can utilise Enumerable#tally and numbered block arguments:a = ["a", "d", "c", "b", "b", "c", "c"]puts a.tally.filter { _2 > 1 }.sort_by { -_2 }.map &:firstHere,...

View Article


Answer by Ja͢ck for Iterate a PHP array from a specific key

If this pull request makes it through, you will be able to do this quite easily:if (seek($array, 'yy', SEEK_KEY)) { while ($data = each($array)) { // Do stuff }}

View Article

Answer by Ja͢ck for Efficiently counting the number of lines of a text file....

Using a loop of fgets() calls is fine solution and the most straightforward to write, however:even though internally the file is read using a buffer of 8192 bytes, your code still has to call that...

View Article

Answer by Ja͢ck for Trying to test my randomiser in rspec by passing specific...

Your weather_randomiser does too many things:It generates a random numberIt maps a random number to a string valueIt updates an instance variableTo make things more testable, you could split those out,...

View Article


Answer by Ja͢ck for Sum values in one column of a 2d array

You need to couple it with array_map() to select the f_count column first:array_sum(array_map(function($item) { return $item['f_count']; }, $arr));Nowadays you can replace the inner function with...

View Article

Answer by Ja͢ck for Filter a flat, associative array by the keys in another...

To get the elements that exist in $arr2 which also exist in $arr1 (i.e. drop elements of $arr2 that don't exist in $arr1), you can intersect based on the key like this:array_intersect_key($arr2,...

View Article

Answer by Ja͢ck for Can you include raw JSON in Guzzle POST Body?

You can send a regular array as JSON via the 'json' request option; this will also automatically set the right headers:$headers = ['NETOAPI_KEY' => env('NETO_API_KEY'),'Accept' =>...

View Article

Answer by Ja͢ck for javascript: stop setInterval after element removal

Have you tried storing the intervalId on the #element itself using $.data?$('#element').mouseover(function() { var $this = $(this); $.post('ajax/ajax.php', function(data) { $('<div...

View Article



Answer by Ja͢ck for Javascript passing arrays to functions by value, leaving...

Inside your function there's this:funcArray = new Array();funcArray = someArray;This won't actually copy someArray but instead reference it, which is why the original array is modified.You can use...

View Article

Answer by Ja͢ck for PHP Regex: match character set OR end of string

To match a string that starts with a slash, followed by six alphanumerics and is then followed by either the end-of-string or something that's not...

View Article

Answer by Ja͢ck for Element ID from document.getElementsByClassName

Using in is not how you should iterate over an array of elements. You should use the .length property and use numeric indexing:for (var i = 0; i < divstopop.length; ++i) { // Get id property from...

View Article

Answer by Ja͢ck for Ruby - functional approach to filtering with index

After many years, Ruby 2.7 ships with Enumerable#filter_map() to make this simpler:stuff.filter_map.with_index { |elem, index| index if elem == '' }

View Article


Answer by Ja͢ck for Search for part of an key in array - PHP

You can use a negative filter (with strpos) instead:foreach ($array as $key => $value) { if (strpos($key, 'array_') !== 0) { unset($array[$key]); }}DemoNote that it modifies the array...

View Article

Answer by Ja͢ck for join enumerable to produce string in Ruby

The code within your question is already as optimal as it gets, but it's possible to remove the condition inside your block:e = ('a'..'z').to_enumjoined_string = e.reduce { |acc, str| acc << '...

View Article

Answer by Ja͢ck for how to generate unique id in php based on current data...

With PHP 7 you can use this to generate a sufficiently random value based on the current timestamp:$s = time() . bin2hex(random_bytes(10));Do note that after 265 years (starting with 11 digits in 2286)...

View Article


Answer by Ja͢ck for creating a random number using MYSQL

This should give what you want:FLOOR(RAND() * 401) + 100Generically, FLOOR(RAND() * (<max> - <min> + 1)) +<min> generates a number between <min> and <max>...

View Article


Answer by Ja͢ck for PHP function to generate v4 UUID

To construct a UUIDv4 you can generate 128 bits worth of random data, patch a few fields to make the data comply with the standard, and then format it as hexadecimal groups.According to RFC 4122 -...

View Article

Answer by Ja͢ck for Fastest way to handle undefined array key

UpdateSince PHP 7 you can accomplish this with the null coalescing operator (keeping in mind that it will bypass existing array element with null value, the same way isset would):return $table[$key] ??...

View Article
Browsing latest articles
Browse All 39 View Live




<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>