function

I don't like Python functions that take two or more iterables. Is it a good idea?

This question came from looking at this question on Stackoverflow. def fringe8((px, py), (x1, y1, x2, y2)): Personally, it's been one of my pet peeves to see a function that takes two arguments with fixed-number iterables (like a tuple) or two or more dictionaries (Like in the Shotgun API). It's just hard to use, because of all the ve...

Multiple actions upon a case statement in Haskell

One last question for the evening, I'm building the main input function of my Haskell program and I have to check for the args that are brought in so I use args <- getArgs case length args of 0 -> putStrLn "No Arguments, exiting" otherwise -> { other methods here} Is there an intelligent way of setting up other methods, or is...

PHP: URL detection (regexp) includes line breaks

I want to have a function which gets a text as the input and gives back the text with URLs made to HTML links as the output. My draft is as follows: function autoLink($text) { return preg_replace('/https?:\/\/[\S]+/i', '<a href="\0">\0</a>', $text); } But this doesn't work properly. For the input text which contains ... http://...

Force download working, but showing invalid when trying to open locally.

Hi, I wrote this function and everything works well till i try to open the downloaded copy and it shows that the file is invalid. Here is my function function download_file() { //Check for download request: if(isset($_GET['file'])) { //Make sure there is a file before doing anything if(is_file($this->path ....

jquery - difference between $.functionName and $.fn.FunctionName

In jQuery, I have seen both the following ways of defining a jQuery function: $.fn.CustomAlert = function() { alert('boo!'); }; $.CustomAlert = function() { alert('boo!'); }; I understand that they are attached to the jQuery object (or $), but what is the difference between the two? When should I use one or the other? Thanks. ...

In matlab, how do I apply a function of two arguments to two cellarrays of equal length?

So I have two cell arrays: A = {2 2 2 2} B = {[1 2] [3 2] [5 5] [7 7]} and a function of two arguments: F = @(a, b) [a * b(1), (b(2) / 3), (b(1) + a) * 22] And I want to apply the function to the two cell arrays like so: idealfun(F, A, B) and have it do the right thing (return a cell array with four cells of 1x3 vectors). Any i...

atol(), atof(), atoi() function behaviours, is there a stable way to convert from/to string/integer ?

In these days i'm playing with the C functions of atol(), atof() and atoi(), from a blog post i find a tutorial and applied: here are my results: void main() char a[10],b[10]; puts("Enter the value of a"); gets(a); puts("Enter the value of b"); gets(b); printf("%s+%s=%ld and %s-%s=%ld",a,b,(atol(a)+atol(b)),a,b,(atol(a)-atol(b))); ge...

Hibernate parameter typing with functions

Hi all, When using hibernate typically it can figure out the type of your parameters by looking at either the property it is against, or hibernate seems to recognise certain types by default (e.g. java.util.Date). However I have some queries which use functions (dateadd). In these queries using a object that has a custom type binding ...

functions in C#

As in c # to create and then call the function? In C + + do so: int func (int value) { value +=2; } But as is done in c #? ...

Invoking jQuery function without an element

So, I use jQuery quite extensively and I am well aware of the "right" way to do the below, but there are times where I want to solve it in a more generic way. I'll explain. So, I may have a link, like this: <a href='menu' class='popup'>Show menu</a>. Now, I have a jQuery function that fires on click for all a.popup that takes the href-a...

C# Memoization of functions with arbitrary number of arguments

I'm trying to create a memoization interface for functions with arbitrary number of arguments, but I'm failing miserably I feel like my solution is not very flexible. I tried to define an interface for a function which gets memoized automatically upon execution and each function will have to implement this interface. Here is an example w...

PDO not working within function

Hi everyone, I am trying to make a function to pull a page's content from a MySQL table using a PDO Prepare statement. My code works just fine outside of the function I defined, but no matter what I do it will not work within the function - I receive the following error: Fatal error: Call to a member function prepare() on a non-object ...

strcmp equivelant for integers (intcmp) in PHP

So we got this function in PHP strcmp(string $1,string $2) // returns -1,0, or 1; We Do not however, have an intcmp(); So i created one: function intcmp($a,$b) { if((int)$a == (int)$b)return 0; if((int)$a > (int)$b)return 1; if((int)$a < (int)$b)return -1; } This just feels dirty. What do you all think? this is par...

Sum of a row of an associative array using PHP?

Is there a php function that returns the sum of a row of an associative array? If not should I just use a counter and a foreach loop? Appreciate it! ...

Write a funtion based on given TestUnit

I need to write a function to satisfy this input -> output list: 0 -> 0 1 -> 1 3 -> 2 4 -> 3 5 -> 5 7 -> 13 9 -> 34 f(x) = ?? ...

using FUNCTION instead of CREATE FUNCTION oracle pl/sql

I see people writing a function with FUNCTION instead "CREATE FUNCTION". When I saw this usage in the web I thought it was a typo or something. But in Oreilly's "Oracle 11g PL/SQL Programming" by Steven Feurenstein, the author had used the same thing. But I get errors when I execute that. Could somebody explain is it legal usage or not?....

Dispatch functions

What exactly are dispatch functions? I've googled them and all is vague. They seem to just be nested blocks/closures inside of other functions? Speaking from a scala/lift point..but i assume it's universal, i've seen them mentioned in ruby as well. ...

string function workout in php

I have the string like this, $inp1 = "3 doses at 0[0,0], 1-2 and 6 Month[6,1] [3,2])"; in this internally, going to take the values of square bracket. How can i take this values in the square bracket? any function is there to return the string like this [0,0] [6,1] [3,2] Thanks in advance for help. ...

How to start a Python script several functions in

Hello, I have a Python script and I want to call it several functions down the script. Example code below: class Name(): def __init__(self): self.name = 'John' self.address = 'Place' self.age = '100' def printName(self): print self.name def printAddress(self): print self.address ...

Passing an array as a function parameter in JavaScript

Hi all, i'd like to call a function using an array as a parameters: var x = [ 'p0', 'p1', 'p2' ]; call_me ( x[0], x[1], x[2] ); // i don't like it function call_me (param0, param1, param2 ) { // ... } Is there a better way of passing the contents of x into call_me()? Ps. I can't change the signature of call_me(), nor the way x...