constants

PHP Tokens - finding user defined constants.

Hi, got a reall head scratcher. Im trying to make a PHP obfuscator ( http://www.actwebdesigns.co.uk/web-design-blog/actobfuscator-free-open-source-php-obfuscator/ ) I've hit a little problem tho. I cant find a guaranteed way of finding a user defined constant. some of my the token_name()'s return as T_STRING and others as T_CONSTANT_E...

What is the Linux equivalent to MAXDWORD?

In Microsoft Visual C++, there is a constant called MAXDWORD defined in winnt.h as follows: #define MAXDWORD 0xffffffff It's useful as a high initial value for a 'double' when one is searching for the lowest value in a collection. Google though I might, I can't find the equivalent in standard headers on Linux, but I'm willing to be...

Django - How to share configuration constants within an app?

It is sometimes beneficial to share certain constants between various code files in a django application. Examples: - Name or location of dump file used in various modules\commands etc - Debug mode on\off for the entire app - Site specific configuration What would be the elegant\pythonic way of doing this? ...

Rails model constants with hash

I have added some constants to a model say MyModel.rb as shown below. MY_CONST = { :foo =>"Some Name for Foo", :bar =>"Some Name for Bar" } Also I have saved string foo as the column value in a table record. @m = MyModel.find(1) @m.column_name #=> foo Now in my view I need to show "Some Name for Foo" as the output for @m.colu...

What is the Clojure equivalent of a "public static final" constant in Java

I'm writing some Clojure code that depends upon a number of constants. They will be used within tight inner loops, so it's important that they will be used and optimised as efficiently as possible by the Clojure compiler+JVM combination. I would normally used a "public static final" constant in Java for the same purpose. What is the be...

Constants for resource types in Android

Are there constants for the various resource types (ie: "drawable") in Android? I want to code some conditional logic based on the return value of getResourceTypeName and I would prefer to avoid hardcoding the resource types. Example: final String type = context.getResources().getResourceTypeName(resid); if ("drawable".equalsIgnoreCas...

variable or constant ?

Is there a benefit of using one over the other ? $lang = isset($_COOKIE['lang']) ? $_COOKIE['lang'] : 'en'; # OR define("LANG" , isset($_COOKIE['lang']) ? $_COOKIE['lang'] : 'en'); Thanks ...

C#: Constants, resources & configuration files for not-configurable values. Best practice

What is the best practice to store constant values that hardly will ever be changed during application life-cycle? For example there are constant messages to show on UI (and you know exactly application will never be localized) or category-ids that are hard-coded in the database. It takes too much time to put everything in config. Is...

Where to store Class Specific named constants in C++

If you have a class that has some named constants, what is the best practive for storing the constants: Option 1: Namespace in Class header So in my class header I will have: class myClass { ... ... }; namespace NamedConstants { const string Bucket = "Bucket"; } Option 2 Member Constants class MyClass { // this goes in th...

Using global variables in CakePHP Shell scripts

Using CakePHP's shell scripts I'm having problems accessing constants, which I normally set within config/bootstrap.php. Is this because using shell scripts I'm not going through the normal dispatcher routine? What's the best practice for defining constants across shell scripts? Thanks. ...

How can I use an NSArray as a global constant?

I'm using a set of Constant.m files, one per target, to define specific things for each target. For example: // Constants.h extern NSString * const kDatabaseFileName; //Constants.m NSString * const kDatabaseFileName = @"target_one.sqlite"; I'd also like to define an NSArray for each of my targets: NSArray * const kLabelNames = [[NSAr...

WCF data contract

I have a data contract and I defined some constant variables in it and have [DataMember] tag for each constant variables. However, my client side does not retrieve those constant variables. I want those constant variables synchronized with the WCF service every time I update the metadata of my WCF service at my client side. I don't want ...

Compiler problem in a (very) simple C++ program that gets numeric input from a file.

#include <iostream> #include <fstream> #include <cstdlib> using namespace std; const int FILENAME_MAX=20; int main() { ifstream input; char name[FILENAME_MAX + 1]; int value; do { cout << "Enter the filename (maximum of " << (FILENAME_MAX+1) << " characters: "; cin >> name; input.ope...

Decoding integer and other masks in Cocoa

Cocoa has a plethora of integer masks and codes. For instance, NSCommandKeyMask or NSF1FunctionKey, which are clearly defined and documented in the headers. However, some can be archaic and when accessing accessibility attributes, for instance to get the glyph (AXMenuItemCmdGlyph), you're given an integer number like 111, which represen...

How can I set a constant with namespace in the initializers?

Help! in my rails controllers, there is a 'Admin' namespace. (My the structure of the controllers dir is like this : app/controllers: home_controller.rb ... admin/posts_controller.rb admin/pages_controller.rb The 'Admin' will automatically become a Module constant (I know it from the console: 'puts Admin => Module'); And...

What are the actual ms time values for Android's animTime constants?

Android includes config_longAnimTime config_mediumAnimTime config_shortAnimTime but the actual values identified by these constants don't make sense as milliseconds. I'm sure they get compiled into useful values, and I can determine them with code, but I'm sure someone else knows the answer - and, more to the point, I'm sure other pe...

PHP using dirname(__FILE__) on non-dedicated server?

Hi, What I trying to do is to define a constant variable in a config file: DEFINE("PATH", dirname(__FILE__) . "/"); So that, when I want to "include" or redirect, I could do this: include(PATH . "filename.php"); or header("location: " . PATH . "logout/php"); But when I try doing an echo of PATH, I get this result: /home/myDOMA...

Constant Array and Memory Management

Hi, I have defined a constant array in one of my classes as: static const float values[] = {-0.5f, -0.33f, 0.5f, -0.33f, -0.5f, 0.33f,}; In the dealloc method of my class, do I need to free the memory occupied by this field? How do I do it? Should I use NSArrays instead? ...

Segmentation fault while using priority queues

I have a priority queue with elements of a class named A I need elements from this queue which may be lower down the queue (lesses priority). So , I am trying to pop a few elements until i get the element of my choice. Once i get the element of my choice i am planning to push all the elements i stored temporary in an array. I have a loo...

Do you use constants from the implementation in your test cases?

Let's say you have some code like this (in a made-up langague, since it does not matter for this question): constant float PI = 3.14; float getPi() { return PI; } Would you test it like this: testPiIs3point14() { // Test using literal in test case AssertEquals( getPi(), 3.14 ); } Or like this: testPiIs3Point14() { //...