Development reference: Difference between revisions

From Bitpost wiki
No edit summary
No edit summary
Line 106: Line 106:
|-
|-
| ddd gives you a front end.  I need to use it more, compare to other options
| ddd gives you a front end.  I need to use it more, compare to other options
|}
{| class="mw-collapsible mw-collapsed wikitable"
! Create a portable command line C project in Visual Studio
|-
|
    Visual Studio: File -> New -> project
    Visual C++ -> Win32 -> Win32 Console Application
    name: oms_with_emap
    next -> click OFF precompiled header checkbox (even tho it didn't seem to respect it)
    you'll get a _tmain(..., TCHAR*...)
    change it to main(..., char*...)
    change the project to explicitly say "Not using precompiled header"
    remove the f'in stdafx.h
    recompile!  should be clean
    vs will recognize C files and compile accordingly
|}
{| class="mw-collapsible mw-collapsed wikitable"
! Create a portable C++ project in Visual Studio
|-
|
It's probably best to create a *.cpp file with your main() function.
int main( int argc, char * argv[] )
{
    return 0;
}
Then in Visual Studio...
File->New->Project from existing code
C++
(then use mostly defaults on this page, once you provide file location and project name)
Project file location:  <base>\project_name
Project name: project_name
[x] Add files from these folders
    Add subs 
    [x]        <base>\project_name
NEXT
Use Visual Studio
  Console application project
  No ATL, MFC, CLR
NEXT
NEXT
FINISH
|}
|}



Revision as of 21:45, 19 June 2013

c++11 containers
sorted_vector use when doing lots of unsorted insertions and maintaining constant sort would be expensive
map sorted binary search tree; always sorted by key; you can walk through in sorted order
multimap same as map but allows dupe keys; need for this should be pretty rare
unordered_map hashmap; always sorted by key; additional bucket required for hash collisions; no defined order when walking through
unordered_multimap same as map but allows dupe keys; dupes are obviously in the same bucket, and you can walk just the dupes if needed
set
multiset
unordered_set
unordered_multiset
sets are just like maps, except the key is embedded in the object, great idea

but... they are ruined by the constraint that contained items must be const
but... then redeemed by mutable
You can use mutable on the variable that are not part of the key to remove the const!
This changes the constness of the object from binary (completely const) to logical (constness is defined by the developer)
so... set is an excellent way to achieve both encapsulation and logical const

c++11 for loop using lambda
This C++11 for loop is clean and elegant and a perfect way to check if your compiler is ready for c++11:
vector<int> v;
for_each( v.begin(), v.end(), [] (int val)
{
   cout << val;
} );

This is using a lambda function, we should switch from iterators and functors to those - but not quite yet, since we're writing cross-platform code. Do not touch this until we can be sure that all platforms provide compatible C++11 handling. Initial results of for_each support:

  • max os x snow leopard does not understand the lambda function
c++ stl in-memory storage of "major" objects
   where major = need to track a large number of them in a sorted vector; they are heavily referenced outside the vector
   Having a coding revelation!!!

   OBSERVATION ONE

   QObjects cannot normally be copied
       this is by design - their copy constructors and assignment operators are private
       why?  A Qt Object...
           might have a unique QObject::objectName(). If we copy a Qt Object, what name should we give the copy?
           has a location in an object hierarchy. If we copy a Qt Object, where should the copy be located?
           can be connected to other Qt Objects to emit signals to them or to receive signals emitted by them. If we copy a Qt Object, how should we transfer these connections to the copy?
           can have new properties added to it at runtime that are not declared in the C++ class. If we copy a Qt Object, should the copy include the properties that were added to the original?
   in other words, a QObject is a pretty serious object that has the ability to be tied to other objects and resources in ways that make copying dangerous
   isn't this true of all serious objects?  pretty much

   OBSERVATION TWO

   if you have a vector of objects, you often want to track them individually
   if you use a vector of pointers, you can keep the pointer and not worry about vector reallocations - perfect

   OBSERVATION THREE

   STL provides everything you need to keep vectors of your pointers, iterate thru them, etc.
   for a vector of any substantial size, you want to keep objects sorted so you can find them quickly
   that's what my sorted_vector class is for
   following STL practices, to get sorting, you have to provide operator< for whatever is in your vector
   BUT... you are not allowed to do operator<(const MyObjectPtr* right) because it would require a reference to a pointer which is not allowed
   BUT... you can provide a FUNCTOR to do the job, then provide it when sorting/searching
   a functor is basically a structure with a bool operator()(const MyObjectPtr* left, const MyObjectPtr* right)
   once c++11 is ready, consider using lambda functions instead
c++ stl reverse iterator skeleton
From SGI...
reverse_iterator rfirst(V.end());
reverse_iterator rlast(V.begin());

while (rfirst != rlast) 
{
    cout << *rfirst << endl;
    ...
    rfirst++;
}
c++ stl reading a binary file
c/c++ gdb debugging
(gdb) help break
Set breakpoint at specified line or function.
Argument may be line number, function name, or "*" and an address.
If line number is specified, break at start of code for that line.
If function is specified, break at start of code for that function.
If an address is specified, break at that exact address.
With no arg, uses current execution address of selected stack frame.
This is useful for breaking on return to a stack frame.

Multiple breakpoints at one place are permitted, and useful if conditional.    

Do "help breakpoints" for info on other commands dealing with breakpoints.
ddd gives you a front end. I need to use it more, compare to other options
Create a portable command line C project in Visual Studio
   Visual Studio: File -> New -> project
   Visual C++ -> Win32 -> Win32 Console Application
   name: oms_with_emap
   next -> click OFF precompiled header checkbox (even tho it didn't seem to respect it)
   you'll get a _tmain(..., TCHAR*...)
   change it to main(..., char*...)
   change the project to explicitly say "Not using precompiled header"
   remove the f'in stdafx.h
   recompile!  should be clean
   vs will recognize C files and compile accordingly
Create a portable C++ project in Visual Studio

It's probably best to create a *.cpp file with your main() function.

int main( int argc, char * argv[] )
{ 
    return 0;
}

Then in Visual Studio...

File->New->Project from existing code
C++
(then use mostly defaults on this page, once you provide file location and project name)
Project file location:  <base>\project_name
Project name: project_name
[x] Add files from these folders
   Add subs  
   [x]        <base>\project_name
NEXT
Use Visual Studio
  Console application project
  No ATL, MFC, CLR
NEXT
NEXT
FINISH
php debugging
Tail these:
tail -f /var/log/apache2/sitelogs/thedigitalage.org/ssl_error_log
tail -f /var/log/ampache-tda/ampache.(today).log
This leads to too much noise, not needed...
emacs /etc/php/apache2-php5.3/php.ini
  display_errors = On
/etc/init.d/apache restart
java eclipse project layout format
* Eclipse workspace (can also be the top version-control folder) ** project folder (typically one "app" that you can "run") *** package(s) (named something like "com.developer.project.application") **** classes (each class is contained in one file)
SQL Server 2008+ proper upsert using MERGE
       -- We need an "upsert": if record exists, update it, otherwise insert.
       -- There are several options to do that.
       -- Trying to do it correctly means...
       --		1) use a lock or transaction to make the upsert atomic
       --		2) use the best-available operation to maximize performance
       -- SQL Server 2008 has MERGE which may be slightly more efficient than 
       -- separate check && (insert||update) steps.  And we can do it with
       -- a single lock instead of a full transaction (which may be better?).
       -- It's messy to code up though since three blocks of fields must be specified.  
       -- Cest la vie.
       MERGE [dbo].[FACT_DCSR_RemPeriodMonthlyReport] WITH (HOLDLOCK) AS rpmr
       USING (SELECT @ID AS ID) AS new_foo
             ON rpmr.ID = new_foo.ID



               @last_months_year as DCSRYear,
               @last_month as DCSRMonth,
               @last_month_name as MonthName,
               Device_Type_ID,




       WHEN MATCHED THEN
           UPDATE
                   SET f.UpdateSpid = @@SPID, 
                   UpdateTime = SYSDATETIME() 
       WHEN NOT MATCHED THEN
           INSERT
             (
                   ID, 
                   InsertSpid, 
                   InsertTime
             )
           VALUES
             (
                   new_foo.ID, 
                   @@SPID, 
                   SYSDATETIME()
             );
git recreate repo
git clone git+ssh://m@thedigitalmachine.com/home/m/development/thedigitalage/ampache-with-hangthedj-module
cd ampache-with-hangthedj-module
git checkout -b daily_grind origin/daily_grind
bash chmod dirs
find /path/to/base/dir -type d -exec chmod g+x {} \;
Web Services
Firefox Addon development

mediawiki collapsible skeleton
#replace#
mediawiki collapsible example
DJs are kept on the active Active djs are maintained Active djs are maintained Active djs are maintained Active djs are maintained Active djs are maintained Active djs are maintained djs list when both the server and the dj are enabled.
All djs are shown in the prefs djs list.

Line 2

Line 3

All djs are shown in the prefs djs list.All djs are shown in the prefs djs list.All djs are shown in the prefs djs list.All djs are shown in the prefs djs list.All djs are shown in the prefs djs list.

cd /var/www/localhost/htdocs/mediawiki
emacs LocalSettings_redirector.php (to hardcode each site)
php maintenance/update.php
(repeat for each site)
emacs LocalSettings_redirector.php (to reset dynamic behavior)