Rectangle 27 8

Looking at that gem's documentation, it sounds like you need an API key before you can run the exists method:

Fine, but how about the rest of the API as advertised at en.gravatar.com/site/implement/xmlrpc? Well, for that you need either the users Gravatar password, or their API key:

api.exists?("another@example.com") #=> true or false, depending on whether the specified email exists.

If the user doesn't have a gravatar, an image will be generated for them based on the email (at least that has been my experience). I've used the gem gravatar_image_tag - http://rubygems.org/gems/gravatar_image_tag which lets you change the default gravatar image.

well, i just did not catch the politics gem vs gravatar. As in written in gravatar documentation u can easy pass d= parameter to an image request: 404: do not load any image if none is associated with the email hash, instead return an HTTP 404 (File Not Found) response. That i was looking for in the mentioned gem

ruby on rails - How should i check if gravatar exist? - Stack Overflow

ruby-on-rails gravatar
Rectangle 27 4

I experienced the same issue. I found out that there is a rader open for this. In the comments I found a tip that I implemented in a function that does a retry.

The arguments array is an array of enum values where the base type is String. I use that for the app arguments.

Unfortunately this is still not full prove. In my case the number of failures went down considerably, but did not go away.

var app: XCUIApplication = XCUIApplication()
public func tryLaunch<T>(_ arguments: [T], _ counter: Int = 10) where T: RawRepresentable {
    sleep(3)
    XCUIApplication().terminate()
    sleep(3)

    app = XCUIApplication()
    app.launchArguments = arguments.map { $0.rawValue as! String }
    app.launch()
    sleep(3)
    if !app.exists && counter > 0 {
        tryLaunch(arguments, counter - 1)
    }
}
Error Domain=FBSOpenApplicationServiceErrorDomain Code=1 "The request to open "com.apple.test.SomeTest-Runner"

ios - XCTests failing to launch app in simulator intermittently - Stac...

ios xcode xctest fastlane
Rectangle 27 1

Basically, you need LEFT JOIN and it looks like you also need generate_series() to provide the full set of days:

SELECT d.date
     , a.date IS NOT NULL AS a_exists
     , COALESCE(b.status, 'status_missing') AS status
FROM (
   SELECT date::date
   FROM   generate_series('2015-06-01'::date
                        , '2015-06-30'::date
                        , interval '1 day') date
    ) d
LEFT   JOIN sis.table_a a USING (date)
LEFT   JOIN sis.table_b b USING (thing_id)
ORDER  BY 1;

Use sargable WHERE conditions. What you had cannot use a plain index on date and has to default to a much more expensive sequential scan. (There are no more WHERE conditions in my final query.)

Aside: don't use the basic type name (and reserved word in standard SQL) date as identifier.

postgresql - Creating 'Empty' Records for Days of the Month Without Re...

postgresql calendar
Rectangle 27 1

Basically, you need LEFT JOIN and it looks like you also need generate_series() to provide the full set of days:

SELECT d.date
     , a.date IS NOT NULL AS a_exists
     , COALESCE(b.status, 'status_missing') AS status
FROM (
   SELECT date::date
   FROM   generate_series('2015-06-01'::date
                        , '2015-06-30'::date
                        , interval '1 day') date
    ) d
LEFT   JOIN sis.table_a a USING (date)
LEFT   JOIN sis.table_b b USING (thing_id)
ORDER  BY 1;

Use sargable WHERE conditions. What you had cannot use a plain index on date and has to default to a much more expensive sequential scan. (There are no more WHERE conditions in my final query.)

Aside: don't use the basic type name (and reserved word in standard SQL) date as identifier.

postgresql - Creating 'Empty' Records for Days of the Month Without Re...

postgresql calendar
Rectangle 27 5

Seems like i found the problem

sudo apt-get install php-apc
sudo /etc/init.d/apache2 restart

Installed an old version of APC on my machine. In that version apc.shm_size=30M has to be configuered without the M in the memory size. Thus new versions of APC use apc.shm_size=30M old version apc.shm_size=30. Once I made the change Apache restarted without a glitch.

Confirmed with Debian Squeeze. Version of php-apc is the same in lucid, maverick and natty releases of Ubuntu and Debian Squeeze. So users of all those versions should not use M when specifying apc.shm_size.

php - APC configuration on Ubuntu 10.4. Problem with apc.shm_size, apc...

php performance apache ubuntu apc
Rectangle 27 253

Memcached is a distributed caching system, whereas APC is non-distributed - and mainly an opcode cache.

If (and only if) you have a web application which has to live on different webservers (loadbalancing), you have to use memcache for distributed caching. If not, just stick to APC and its cache.

You should always use an opcode cache, which APC is (also APC will get integrated into php6 iirc, so why not start using it now).

You can/should use both for different purposes.

opcode

@Karsten If you have different servers (like a cloud loadbalaced environment) as long as you don't need to maintain/share state across them, APC will also work fine as a straight up memory cache--though maybe not as optimal as each cloud instance will have to warm their own cache...

An opcode cache is one that compiles the plain PHP code into machine code ("opcode") and then stores it in the compiled form for future requests (until it detects the original PHP file has changed). This means that PHP doesn't have to run this compile step on every single request, saving some time. It's just one of the ways to help ensure a speedy site (amongst many others).

Can memechached be used in non-distributed system instead of APC? It will be good to keep only one if in the future you will have more machines. right? Or use them both, one for opcode and the other for extensible caching?

php - Memcached vs APC which one should I choose? - Stack Overflow

php caching memcached apc
Rectangle 27 4

You should check the kernel max size for shared memory. On debian-like distribution it's quite low (and ubuntu is a debian-like). Altering it via sysctl.conf could help you.? Get current value with:

sysctl -a  | grep shmmax

It's a value in Bytes.

This could explain apache crash when you set a too big number (but you should have something about it in error.log).

apc.shm_segments

If you've configured APC to use memory mapped files (with the --enable-mmap option), the shm_segments setting is ignored unless you specify a file mask via the mmap_file_mask setting. Which could be fixed by giving a value to apc.mmap_file_mask configuration setting (see link).

But as said in this comment, using several shared segments is certainly worst as using a big one. there is at least two big application which makes heavy use of big shared memory and which always needs an alteration of the kernel settings for that, it's Varnish and PostgreSQL. Both made the choice of using a big shared segment instead of several.

hi, thanks for your reply! tried to increase the shared memory size via kernel.shmmax = 134217728 unfortunately this didn't solve my problem. Opened a new question describing the problems more in detail on serverfault

php - APC configuration on Ubuntu 10.4. Problem with apc.shm_size, apc...

php performance apache ubuntu apc
Rectangle 27 1815

In JavaScript, everything is 'truthy' or 'falsy', and for numbers 0 (and NaN) means false, everything else true. So you could write:

if ($(selector).length)

You don't need that >0 part.

@abhirathore2006 If you use an id selector and the element doesn't exist then length is 0 and doesn't throw exceptions.

NaN != false

@Robert and [] + [] = ""... ahh I love javascript

@James & Robert: the coolest comments here, i would like just to be able to see in SO a question like: "Where are the Javascript black holes?"

javascript - Is there an "exists" function for jQuery? - Stack Overflo...

javascript jquery
Rectangle 27 1283

$('elemId').length
$('#elemId').length
---^

With vanilla JavaScript, you don't need the hash (#) e.g. document.getElementById('id_here') , however when using jQuery, you do need to put hash to target elements based on id just like CSS.

@trejder Most likely the poster was unaware of Vanilla JS and when they said "vanilla JavaScript" they actually meant base JavaScript ("vanilla" as in "plain", "unadorned).

@trejder Looks like "Vanilla JS" is exactly the same as base Javascript anyway (the downloaded file is always empty) - someone just decided to make a sales pitch for base Javascript.

Yeah, that website is mocking the need for a framework called "Vanilla JS" which is nothing but JavaScript itself. @trejder should read a little more carefully.

You "don't need the hash" only if you use the wrong function. document.querySelector('#id_here') requires the hash sign just as much as the jQuery equivalent $('#id_here').

javascript - Check if element exists in jQuery - Stack Overflow

javascript jquery
Rectangle 27 380

The best and most efficient way is to catch the "table not found" exception: this avoids the overhead of checking if the table exists twice; and doesn't suffer from the problem that if the DROP fails for some other reason (that might be important) the exception is still raised to the caller:

BEGIN
   EXECUTE IMMEDIATE 'DROP TABLE mytable';
EXCEPTION
   WHEN OTHERS THEN
      IF SQLCODE != -942 THEN
         RAISE;
      END IF;
END;

ADDENDUM For reference, here are the equivalent blocks for other object types:

BEGIN
  EXECUTE IMMEDIATE 'ALTER TABLE ' || table_name
            || ' DROP CONSTRAINT ' || constraint_name;
EXCEPTION
  WHEN OTHERS THEN
    IF SQLCODE != -2443 THEN
      RAISE;
    END IF;
END;
BEGIN
  DBMS_SCHEDULER.drop_job(job_name);
EXCEPTION
  WHEN OTHERS THEN
    IF SQLCODE != -27475 THEN
      RAISE;
    END IF;
END;
BEGIN
  EXECUTE IMMEDIATE 'DROP PACKAGE ' || package_name;
EXCEPTION
  WHEN OTHERS THEN
    IF SQLCODE != -4043 THEN
      RAISE;
    END IF;
END;
BEGIN
  EXECUTE IMMEDIATE 'DROP FUNCTION ' || function_name;
EXCEPTION
  WHEN OTHERS THEN
    IF SQLCODE != -4043 THEN
      RAISE;
    END IF;
END;
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLESPACE' || tablespace_name;
EXCEPTION
  WHEN OTHERS THEN
    IF SQLCODE != -959 THEN
      RAISE;
    END IF;
END;

And for dropping a USER, the SQLCODE to ignore is -1918.

One needs to write a procedure do do that? Isn't there a better way to do that?

@WilsonFreitas - No, you don't need to write a procedure. You can use an anonymous block, as in the example here.

If I add many EXECUTE IMMEDIATE 'DROP TABLE mytable'; sentences (one for each table in the script), do I have to put one exception handler for each one, or is it enough to wrap all the senteces in one BEGIN ... EXCEPTION ... END; block?

@jpmc26: The equivalent for MS SQL is IF OBJECT_ID('TblName') IS NOT NULL DROP TABLE TblName. It seems the verbosity of a SQL language is proportional to the price.

sql - Oracle: If Table Exists - Stack Overflow

sql oracle sql-drop
Rectangle 27 1163

jQuery.fn.exists = function(){ return this.length > 0; }

if ($(selector).exists()) {
    // Do something
}

I just write: if( $(selector).length ){ ... } without the '> 0'

Your $.fn.exists example is really, really horrible, and I hope nobody uses it. Youre replacing a property lookup (cheap!) with two function calls, which are much more expensiveand one of those function calls recreates a jQuery object that you already have, which is just silly.

@redsquare: Code readability is the best rationale for adding this sort of function on jQuery. Having something called .exists reads cleanly, whereas .length reads as something semantically different, even if the semantics coincide with an identical result.

@quixoto, sorry but .length is a standard across many languages that does not need wrapping. How else do you interpret .length?

In my opinion, it's at least one logical indirection from the concept of "a list length that is greater than zero" to the concept of "the element(s) I wrote a selector for exist". Yeah, they're the same thing technically, but the conceptual abstraction is at a different level. This causes some people to prefer a more explicit indicator, even at some performance cost.

javascript - Is there an "exists" function for jQuery? - Stack Overflo...

javascript jquery
Rectangle 27 40

Memcached if you need to preserve state across several web servers (if you're load balanced and it's important that what's in the cache is the same for all servers).

APC if you just need access to quick memory to read (& write) on a (or each) server.

Remember APC can also compile and speed up your script execution time. So you could for example be using APC for increased execution performance, while using memcached for cache storage.

APC can cache storage too.... Or?

2014 update: PHP 5.5 will nativly include Zend Optimizer Plus (which is only for opcache, so not for user cache) and it seems APC will not be developed beyond PHP 5.4? However there is now APCu pecl.php.net/package/APCu, which took only the user cache parts of APC

php - Memcached vs APC which one should I choose? - Stack Overflow

php caching memcached apc
Rectangle 27 1815

In JavaScript, everything is 'truthy' or 'falsy', and for numbers 0 (and NaN) means false, everything else true. So you could write:

if ($(selector).length)

You don't need that >0 part.

@abhirathore2006 If you use an id selector and the element doesn't exist then length is 0 and doesn't throw exceptions.

NaN != false

@Robert and [] + [] = ""... ahh I love javascript

@James & Robert: the coolest comments here, i would like just to be able to see in SO a question like: "Where are the Javascript black holes?"

javascript - Is there an "exists" function for jQuery? - Stack Overflo...

javascript jquery
Rectangle 27 1162

jQuery.fn.exists = function(){ return this.length > 0; }

if ($(selector).exists()) {
    // Do something
}

I just write: if( $(selector).length ){ ... } without the '> 0'

Your $.fn.exists example is really, really horrible, and I hope nobody uses it. Youre replacing a property lookup (cheap!) with two function calls, which are much more expensiveand one of those function calls recreates a jQuery object that you already have, which is just silly.

@redsquare: Code readability is the best rationale for adding this sort of function on jQuery. Having something called .exists reads cleanly, whereas .length reads as something semantically different, even if the semantics coincide with an identical result.

@quixoto, sorry but .length is a standard across many languages that does not need wrapping. How else do you interpret .length?

In my opinion, it's at least one logical indirection from the concept of "a list length that is greater than zero" to the concept of "the element(s) I wrote a selector for exist". Yeah, they're the same thing technically, but the conceptual abstraction is at a different level. This causes some people to prefer a more explicit indicator, even at some performance cost.

javascript - Is there an "exists" function for jQuery? - Stack Overflo...

javascript jquery
Rectangle 27 1283

$('elemId').length
$('#elemId').length
---^

With vanilla JavaScript, you don't need the hash (#) e.g. document.getElementById('id_here') , however when using jQuery, you do need to put hash to target elements based on id just like CSS.

@trejder Most likely the poster was unaware of Vanilla JS and when they said "vanilla JavaScript" they actually meant base JavaScript ("vanilla" as in "plain", "unadorned).

@trejder Looks like "Vanilla JS" is exactly the same as base Javascript anyway (the downloaded file is always empty) - someone just decided to make a sales pitch for base Javascript.

@DerrickCoetzee Ah, that sounds reasonable! :] Language barrier, huh? :] :] :]

Yeah, that website is mocking the need for a framework called "Vanilla JS" which is nothing but JavaScript itself. @trejder should read a little more carefully.

You "don't need the hash" only if you use the wrong function. document.querySelector('#id_here') requires the hash sign just as much as the jQuery equivalent $('#id_here').

javascript - Check if element exists in jQuery - Stack Overflow

javascript jquery
Rectangle 27 1279

$('elemId').length
$('#elemId').length
---^

With vanilla JavaScript, you don't need the hash (#) e.g. document.getElementById('id_here') , however when using jQuery, you do need to put hash to target elements based on id just like CSS.

@trejder Most likely the poster was unaware of Vanilla JS and when they said "vanilla JavaScript" they actually meant base JavaScript ("vanilla" as in "plain", "unadorned).

@trejder Looks like "Vanilla JS" is exactly the same as base Javascript anyway (the downloaded file is always empty) - someone just decided to make a sales pitch for base Javascript.

Yeah, that website is mocking the need for a framework called "Vanilla JS" which is nothing but JavaScript itself. @trejder should read a little more carefully.

You "don't need the hash" only if you use the wrong function. document.querySelector('#id_here') requires the hash sign just as much as the jQuery equivalent $('#id_here').

javascript - Check if element exists in jQuery - Stack Overflow

javascript jquery
Rectangle 27 6

Generally, session data is something which should be treated as volatile in any situation. The user can always choose to eliminate the cookie themselves at any point (if you are using cookies, of course). For this reason, I see no problem with using memcached for session data.

For me, I'd just keep it simple - no need for a DB fallback unless you absolutely must never lose the user's session in the event of a memcached server failure. As I said at the beginning, I always treat sessions as purely volatile in any case and don't really store anything of any significance in them.

php - Using memcached/APC for session storage? - Stack Overflow

php session memcached apc
Rectangle 27 328

Determines whether the List(T) contains elements that match the conditions defined by the specified predicate.

This exists since .NET 2.0, so before LINQ. Meant to be used with the Predicate delegate, but lambda expressions are backward compatible. Also, just List has this (not even IList)

Determines whether any element of a sequence satisfies a condition.

This is new in .NET 3.5 and uses Func(TSource, bool) as argument, so this was intended to be used with lambda expressions and LINQ.

I later made a post in another thread where I listed all the Linq "equivalents" of the .NET 2 List<> instance methods.

c# - Linq .Any VS .Exists - What's the difference? - Stack Overflow

c# linq collections
Rectangle 27 107

declare
   c int;
begin
   select count(*) into c from user_tables where table_name = upper('table_name');
   if c = 1 then
      execute immediate 'drop table table_name';
   end if;
end;

That's for checking whether a table in the current schema exists. For checking whether a given table already exists in a different schema, you'd have to use all_tables instead of user_tables and add the condition all_tables.owner = upper('schema_name')

+1 This is better because do not relay on exception decoding to understand what to do. Code will be easier to mantain and understand

Agree with @daitangio - performance generally doesn't trump maintainability with run-once deployment scripts.

I would be interested to understand if implicit-commit plays a part here. You would want the SELECT and DROP to be inside the same transaction. [ Obviously ignoring any subsequent DDL that may be executed. ]

@Matthew, the DROP is a DDL command, so it will first issue a COMMIT, drop the table, then issue a 2nd COMMIT. Of course, in this example there is no transaction (since it's only issued a query) so it makes no difference; but if the user had previously issued some DML, it will be implicitly committed before any DDL is executed.

sql - Oracle: If Table Exists - Stack Overflow

sql oracle sql-drop
Rectangle 27 724

if (typeof me.onChange !== "undefined") { 
    // safe to use the function
}
if (typeof me.onChange === "function") { 
    // safe to use the function
}

=== 'function' would be better than != 'undefined'

@James, because that statement actually throws an undefined exception in the JavaScript. I tried it.

@UpTheCreek, it would be a bit dangerous as a general solution since older versions of IE treat certain functions as objects, e.g. typeof window.alert === 'object'.

@BornToCode because then me.onChange could be anything evaluating to true, not necessarily a function (e.g. it could be a boolean, a string, etc). For example see jsfiddle.net/j5KAF/1

How to check if function exists in JavaScript? - Stack Overflow

javascript