Rectangle 27 3

I think the Taglist plugin is what you are looking for. It shows functions, classes etc. in a sidebar and is designed to make source code browsing a lot easier.

vim - displaying functions in c using vi - Stack Overflow

vim editor
Rectangle 27 5

This is because the interactive interpreter displays the return value of any expression you type.

The function you posted has two lines. In the first line, it print()s the value to the standard output. The second returns the same value out of the function. As I stated above, this also gets written to the standard output in the interactive interpreter.

If you were to run your script via the command line (i.e. not in the interactive interpreter:

python myscript.py

You would notice that this return value is no longer printed to the standard output.

python - Outputs: functions vs. functions assigned to variables - Stac...

python function variable-assignment function-calls
Rectangle 27 34

There is an instrumenting (function-accurate) profiler for MS VC 7.1 and higher called MicroProfiler. You can get it here (x64) or here (x86). It doesn't require any modifications or additions to your code and is able of displaying function statistics with callers and callees in real-time without the need of closing application/stopping the profiling process.

It integrates with VisualStudio, so you can easily enable/disable profiling for a project. It is also possible to install it on the clean machine, it only needs the symbol information be located along with the executable being profiled.

This tool is useful when statistical approximation from sampling profilers like Very Sleepy isn't sufficient.

Rough comparison shows, that it beats AQTime (when it is invoked in instrumenting, function-level run). The following program (full optimization, inlining disabled) runs three times faster with micro-profiler displaying results in real-time, than with AQTime simply collecting stats:

void f()
{
    srand(time(0));

    vector<double> v(300000);

    generate_n(v.begin(), v.size(), &random);
    sort(v.begin(), v.end());
    sort(v.rbegin(), v.rend());
    sort(v.begin(), v.end());
    sort(v.rbegin(), v.rend());
}

It's easy to use and super-fast profiler. Only one issue I didn't solve is a problem that after I finished debugging, profiler window didn't close automatically and you have to kill it through task manager (without that you can't recompile your project).

I found that after I close my app by regular CLOSE button, profiler window can be closed regularly too. But when I exit app by SHIFT+F5 shortcut (Stop debugging VS command), profiler window close button is disabled.

Does not work with VS 2015.

This is really really good! Should be ranked way higher! Super simple to install and run, and gives you most of what you need to know. My second choice is Windows Performance Analyzer: geekswithblogs.net/akraus1/archive/2015/04/21/163342.aspx

What's the best free C++ profiler for Windows? - Stack Overflow

c++ windows profile
Rectangle 27 34

There is an instrumenting (function-accurate) profiler for MS VC 7.1 and higher called MicroProfiler. You can get it here (x64) or here (x86). It doesn't require any modifications or additions to your code and is able of displaying function statistics with callers and callees in real-time without the need of closing application/stopping the profiling process.

It integrates with VisualStudio, so you can easily enable/disable profiling for a project. It is also possible to install it on the clean machine, it only needs the symbol information be located along with the executable being profiled.

This tool is useful when statistical approximation from sampling profilers like Very Sleepy isn't sufficient.

Rough comparison shows, that it beats AQTime (when it is invoked in instrumenting, function-level run). The following program (full optimization, inlining disabled) runs three times faster with micro-profiler displaying results in real-time, than with AQTime simply collecting stats:

void f()
{
    srand(time(0));

    vector<double> v(300000);

    generate_n(v.begin(), v.size(), &random);
    sort(v.begin(), v.end());
    sort(v.rbegin(), v.rend());
    sort(v.begin(), v.end());
    sort(v.rbegin(), v.rend());
}

It's easy to use and super-fast profiler. Only one issue I didn't solve is a problem that after I finished debugging, profiler window didn't close automatically and you have to kill it through task manager (without that you can't recompile your project).

I found that after I close my app by regular CLOSE button, profiler window can be closed regularly too. But when I exit app by SHIFT+F5 shortcut (Stop debugging VS command), profiler window close button is disabled.

Does not work with VS 2015.

This is really really good! Should be ranked way higher! Super simple to install and run, and gives you most of what you need to know. My second choice is Windows Performance Analyzer: geekswithblogs.net/akraus1/archive/2015/04/21/163342.aspx

What's the best free C++ profiler for Windows? - Stack Overflow

c++ windows profile
Rectangle 27 34

Add Thumbnails in Manage Posts/Pages List

You can add this to your functions to display to the Manage/Edit Post and Pages List a new column with the thumbnail preview.

/****** Add Thumbnails in Manage Posts/Pages List ******/
if ( !function_exists('AddThumbColumn') && function_exists('add_theme_support') ) {

    // for post and page
    add_theme_support('post-thumbnails', array( 'post', 'page' ) );

    function AddThumbColumn($cols) {

        $cols['thumbnail'] = __('Thumbnail');

        return $cols;
    }

    function AddThumbValue($column_name, $post_id) {

            $width = (int) 35;
            $height = (int) 35;

            if ( 'thumbnail' == $column_name ) {
                // thumbnail of WP 2.9
                $thumbnail_id = get_post_meta( $post_id, '_thumbnail_id', true );
                // image from gallery
                $attachments = get_children( array('post_parent' => $post_id, 'post_type' => 'attachment', 'post_mime_type' => 'image') );
                if ($thumbnail_id)
                    $thumb = wp_get_attachment_image( $thumbnail_id, array($width, $height), true );
                elseif ($attachments) {
                    foreach ( $attachments as $attachment_id => $attachment ) {
                        $thumb = wp_get_attachment_image( $attachment_id, array($width, $height), true );
                    }
                }
                    if ( isset($thumb) && $thumb ) {
                        echo $thumb;
                    } else {
                        echo __('None');
                    }
            }
    }

    // for posts
    add_filter( 'manage_posts_columns', 'AddThumbColumn' );
    add_action( 'manage_posts_custom_column', 'AddThumbValue', 10, 2 );

    // for pages
    add_filter( 'manage_pages_columns', 'AddThumbColumn' );
    add_action( 'manage_pages_custom_column', 'AddThumbValue', 10, 2 );
}
plugins functions customization admin pluggable
Rectangle 27 30

Auto Extract the First Image from the Post Content

This code will automatically extract the first image associated with a post and allow you to display/use it by calling the getImage function.

// AUTOMATICALLY EXTRACT THE FIRST IMAGE FROM THE POST 
function getImage($num) {
    global $more;
    $more = 1;
    $link = get_permalink();
    $content = get_the_content();
    $count = substr_count($content, '<img');
    $start = 0;
    for($i=1;$i<=$count;$i++) {
        $imgBeg = strpos($content, '<img', $start);
        $post = substr($content, $imgBeg);
        $imgEnd = strpos($post, '>');
        $postOutput = substr($post, 0, $imgEnd+1);
        $postOutput = preg_replace('/width="([0-9]*)" height="([0-9]*)"/', '',$postOutput);;
        $image[$i] = $postOutput;
        $start=$imgEnd+1;
    }
    if(stristr($image[$num],'<img')) { echo '<a href="'.$link.'">'.$image[$num]."</a>"; }
    $more = 0;
}

correct but this one works differently and fixes various issues which get_the_image does not take into account

What does it do differently than the get_the_image script?

@matt -- In wordpress there are different ways that images can be added to posts and i think the get_the_image script just looks at one of those. This checks to see if there is a featured image and uses that one first if available, next I think it checks for the first image added to the post content and if that is not found it checks the media gallery for the image with the highest sort order (at least thats how I remember the order going).

i suggest wordpress.org/extend/plugins/auto-post-thumbnail Automatically generate the Post Thumbnail (Featured Thumbnail) from the first image in post or any custom post type only if Post Thumbnail is not set

plugins functions customization admin pluggable
Rectangle 27 22

This is a piece of code I wrote to make use of the WP_DEBUG constants that are normally disabled by default. Well I created a way to not only enable WP_DEBUG so you can use it on a live site with no negative side-effects, but I also made use of the other debugging constants for forcing errors to be displayed, and for creating a log file of the errors and Notices in the /wp-content directory.

Drop this code in your wp-config.php file ( AFTER YOU SAVE A BACKUP JUST IN CASE ) and then you can pass the ?debug=1, 2, or 3 parameters at the end of any url on your site.

?debug=1 = shows all errors/notices ?debug=2 = forces them to be displayed ?debug=3 = creates a debug.log file of all errors in /wp-content dir.

/**
* Written by Jared Williams - http://new2wp.com
* @wp-config.php replace WP_DEBUG constant with this code
* Enable WP debugging for usage on a live site
* http://core.trac.wordpress.org/browser/trunk/wp-includes/load.php#L230
* Pass the '?debug=#' parameter at the end of any url on site
*
* http://example.com/?debug=1, /?debug=2, /?debug=3
*/
if ( isset($_GET['debug']) && $_GET['debug'] == '1' ) {
    // enable the reporting of notices during development - E_ALL
    define('WP_DEBUG', true);
} elseif ( isset($_GET['debug']) && $_GET['debug'] == '2' ) {
    // must be true for WP_DEBUG_DISPLAY to work
    define('WP_DEBUG', true);
    // force the display of errors
    define('WP_DEBUG_DISPLAY', true);
} elseif ( isset($_GET['debug']) && $_GET['debug'] == '3' ) {
    // must be true for WP_DEBUG_LOG to work
    define('WP_DEBUG', true);
    // log errors to debug.log in the wp-content directory
    define('WP_DEBUG_LOG', true);
}

I'm still working on a way to make this either password protected, or preferrably somehow make it work on if (current_user_can('manage_themes') and is_logged_in().

We use something similar to setup live, staging and dev database connection details.

plugins functions customization admin pluggable
Rectangle 27 8

You can use infoCallback option to define a function that will be called when table information is about to be displayed.

For example, default behavior can be achieved with the code below.

var table = $('#example').DataTable({
   "infoCallback": function(settings, start, end, max, total, pre){
      return "Showing " + start + " to " + end + " of " + total + " entries"
         + ((total !== max) ? " (filtered from " + max + " total entries)" : "");
   }        
});

You need to adjust the numbers accordingly to avoid counting the headings.

Alternative solution would be to use JavaScript and not the static HTML to alphabetize table content, similarly to Row grouping example.

Then information panel would contain correct numbers automatically because header rows are added dynamically as additional nodes that are not counted by DataTables as rows.

jquery - How to modify row counts when displaying alphabetized search ...

jquery django datatables datatables-1.10
Rectangle 27 20

New Roles and Capabilities - Only run once!

You only need to uncomment one of these blocks, load any page and then comment them again!

/* Capabilities */

// To add the new role, using 'international' as the short name and
// 'International Blogger' as the displayed name in the User list and edit page:
/*
add_role('international', 'International Blogger', array(
    'read' => true, // True allows that capability, False specifically removes it.
    'edit_posts' => true,
    'delete_posts' => true,
    'edit_published_posts' => true,
    'publish_posts' => true,
    'edit_files' => true,
    'import' => true,
    'upload_files' => true //last in array needs no comma!
));
*/


// To remove one outright or remove one of the defaults:
/* 
remove_role('international');
*/

It's sometimes handy to add/remove from an existing role rather than removing and re-adding one. Again, you only need to uncomment it, reload a page and then comment it again. This will store the role/capability properly in the options table. (This allows you, the developer to control them and removes the overhead of the bulky plugins that do the same thing.) Here I'm changing the author role to delete their published posts (the default), but allowing them the capability to edit their published posts (which isn't possible for this role by default)-- using *add_cap* or *remove_cap*.

/*
$edit_role = get_role('author');
   $edit_role->add_cap('edit_published_posts');
   $edit_role->remove_cap('delete_published_posts');
*/

I keep a spreadsheet with the grid from the Codex page for sites that modify this way, so I can remember how things are set, though leaving the commented out code in your functions.php file will work to. Don't leave these examples uncommented, or it will write to the database with each page load!

The functions I mention above write to a field in the options database. Commenting and uncommenting them is the way to go. There are plugins for user roles, but if you use the functions mention above, you cannot leave these functions running, and you DO NOT need to set them more than once, or set them based on if a specific user is accessing something. If you want that, set that user up with a specific, unique role. And refer to the codex, everything I write above is 100% correct if you do it without a plugin. For nearly every case, you only need to set the user roles once.

@tomcat23: To illustrate, i wrapped it up in a function to only add the role, when it doesn't already exists. Another note: I guess it would be easier to place the role somewhere in the role hierarchy, with retrieving the caps from some built in role and then add/remove the capabilities from the built in role. Would make it more clear and easier to remember if it's caps are placed somewhere between ex. admin and editor. - I hope you don't mind that i edited your answer. If you do, pls role it back. :)

@tomcat23 - Water under the bridge at this point. All I'm saying is, I'm not interested in placing blame, just in having peace for everyone moving forward. :)

@MikeSchinkel Yes, you are right. @kaiser My apologies if I've caused you insult.

@MikeSchinkel: thanks for bringing peace back in. @tomcat23: No, you didn't. I can deal with that sort of criticism. My apologies too.

plugins functions customization admin pluggable
Rectangle 27 10

...so - do I understand correctly - you want to get the whole final output (not just the view) as a string AND not display it to the user? Why dont you just overload the controllers _output() function?

class Your_controller extends CI_Controller
{
       function stuff()
       {
           // do whatever - prep $data etc
           $this->load->view('your_view', $data);
       }

       function _output($output)
       {
           // send $output to your library - get results blah blah
           $result_pdf_file = $this->your_pdf_library_generator($output);

           // Show something else to the user
           echo "hi - I'm not what you expected - but here is your PDF";

           echo $result_pdf_file; // or something like that
       }
 }

This means you can send ANYTHING you like to the output class - but nothing is displayed except what you want.

There are ways to improve this idea (i.e. hooks, variables to turn output on/off etc) - but the simplest would be to have this controller specifically for your pdf_generation command.

I don't see any way of doing step 2 based on the output class documentation. Is it possible to get a view into the output class without displaying it? If so, how? I'm using CI 2.0.3.

The controller _output() documentation is actually in the CI controller documentation, which is why it eluded you.

That is precisely what I was looking for. Had I noticed it first, I would not have been going down the rabbit hole of trying to extend the output class itself. I can see why they put it where they did, but some breadcrumbs leading to it in the output controller docs would have saved some time :)

yeah - i only knew of it from another project. BTW - is your dompdf library wrapper something you might be interested in sharing? I'm literally about to use it in one of my CI projects. If so, my email is in my bio - if not - thats cool I understand - thought'd I just ask and try my luck ;)

I gave a link to the one that inspired the one that I wrote. It's on Github. Can I share the actual wrapper? No, it's not an open project, but I spent literally ten minutes writing one so you have the same start I did. Also, I put a bounty on this which is going your way tomorrow.

Thanks for the link - thats perfect. And thanks for the bounty - I appreciate it :)

Quite welcome. I'll award it as soon as it lets me (not even moderators are immune to the mandatory wait for awarding a bounty).

php - Can I pass data to the Codeigniter output class without displayi...

php codeigniter codeigniter-2 dompdf
Rectangle 27 1

1. Trap the form submit action and display modal dialog

$("form").on("submit", function (e) {
    e.preventDefault();

    // Show your modal
    $("#myModal").modal("show");
});
// This handled the modal close event.
$("#myModal").on("hidden.bs.modal", function() {

    // Remove the submit function from the form.
    $("form").off("submit");

    // Retrieve value from your input by id
    var firstValue = $("#InputId").val();

    // Retrieve value from your input by name
    var secondValue = $("input[name=InputName]").val();

    // Attach new value to the form
    $("<input type='hidden' name='firt-input' value='" + firstValue + "' />")
        .appendTo($("form"));

    // Attach other value to the form
    $("<input type='hidden' name='second-input' value='" + secondValue + "' />")
        .appendTo($("form"));

    // Finally, submit the form.
    // I'd rather use ajax here, but to make things simple, just submit your form.
    $("form").submit();

});

You can either create a new model, create a Wrapper model or just get the extra parameters, like:

public ActionResult Index(MyModel model, string username, string password)
{
   // Validate user/pass
}
public class Wrapper<T>
{
    public T Model { get; set; }
    public string Username { get; set; }
    public string Password { get; set; }
}

public ActionResult Index(Wrapper<MyModel> model)
{
    // Validate user/pass
}

Can we have first name and last name as part of the Actual Model, and pass the entire Model to the MODAL, and access it there?

I mean the way we pass model to partial views, can we pass it to the MODAL also?

How to get values from Bootstrap modal form for use in MVC controller ...

twitter-bootstrap modal-dialog asp.net-mvc-5
Rectangle 27 43

You could do it with the toFixed function, but it's buggy in IE. If you want a reliable solution, look at my answer here.

float_num.toFixed(2);

floating point - JavaScript displaying a float to 2 decimal places - S...

javascript floating-point precision
Rectangle 27 4

When you add autopct to the pie function, the returned format changes resulting in your too many values to unpack message being displayed. The following should work:

pie = plt.pie(values, labels=labels, explode=explode, shadow=True, autopct='%1.1f%%')
plt.legend(pie[0], labels, loc="upper corner")

Giving you the following output:

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

python - displaying numbers with legend on pie chart - Tkinter, Pyplot...

python matplotlib tkinter pie-chart
Rectangle 27 75

function ChangeDasPanel(controllerPath, postParams, f) {
  $.get(
    controllerPath, 
    postParams, 
    function(returnValue) {
      var $DasSpace = $('#DasSpace');
      $DasSpace.hide(
        "slide", { direction: "right" }, 1000, 
        function() {
          $DasSpace.contents().remove();
          $DasSpace.append(returnValue).css("display", "block");
          $DasSpace.show("slide", { direction: "right" }, 1000);
        }
      );
      if (typeof f == "function") f(); else alert('meh');
    }
  );
};

You can pass functions like any other object in JavaScript. Passing in a callback function is straight-forward, you even do it yourself in the $.post() call.

You can decide whether you want to have your callback called as part of the $.post() callback or on its own.

exactly what I've been trying to do for the past 30 minutes. Thanks! helped me out

Thanks for the if (typeof f == "function") f(); part. I have been looking for that!

javascript - How do I write a jquery function that accepts a callback ...

javascript jquery function callback
Rectangle 27 4

Make sure you include the jQueryUI stylesheet as well.

<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/themes/ui-lightness/jquery-ui.css" />

jQuery tabs() function not displaying tabs - Stack Overflow

jquery jquery-ui-tabs
Rectangle 27 2

I solved it eventually by using a WebView that displays a HTML page, that uses the Dracula Graph Library. I transfer the data to the WebView by a Java function that was called from Javascript (on page load) that encoded the data as JSON. Not fancy, but it worked!

Displaying a graph (not charts) in an android app - Stack Overflow

android graph graph-layout
Rectangle 27 62

Well, Firefox (thanks to @Bojangles for detailed information) has Object.toSource() method which prints objects as JSON and function(){}.

Object.toSource() doesn't seem to work for Chrome, is this expected? Or does Chrome not fall under "advanced browsers"? =)

Old thread, just found it through Google. .toSource() is actually Firefox only. Just thought I'd let you know.

How can I display a JavaScript object? - Stack Overflow

javascript javascript-objects
Rectangle 27 7

I resolved this issue by overriding the following function, setting the height of the cells manually:

override func tableView(tableView:UITableView!, heightForRowAtIndexPath indexPath:NSIndexPath)->CGFloat
{
    return 44
}

tableview - Custom cell in Xcode 6 + Swift not displaying - Stack Over...

tableview cell swift xcode6
Rectangle 27 7

You can do this by using the last parameter to FSCopyObjectAsync(), which is a struct of type FSFileOperationClientContext. One of the fields of that struct is info, which is a void* parameter that you can basically use as you see fit. Whatever you assign to that field of the struct you pass into FSCopyObjectAsync() will be passed in turn to your callback function as the last info function parameter there. A void* can be anything, including a pointer to an object, so you can use that to pass the instance of your object that you want to handle the callback.

FSFileOperationClientContext clientContext = {0}; //zero out the struct to begin with

clientContext.info = myProgressIndicator;
//All the other setup code
status = FSCopyObjectAsync (fileOp,
         &source,
         &destination, // Full path to destination dir
         targetFilename,
         kFSFileOperationDefaultOptions,
         statusCallback,
         1.0,
         &clientContext);

Then, in your callback function:

static void statusCallback (FSFileOperationRef fileOp,
       const FSRef *currentItem,
       FSFileOperationStage stage,
       OSStatus error,
       CFDictionaryRef statusDictionary,
       void *info )
{
    NSProgressIndicator* fileProgressIndicator = (NSProgressIndicator*)info;
    [fileProgressIndicator setDoubleValue:(double)floatBytesCompleted];
    [fileProgressIndicator displayIfNeeded];
}

Brian thanks!!! Now I see it, the solution seems so straightforward! I ended up initializing a class instance to handle the progress panel completely and passed that class instance into the clientContext. I was able to update the progress bar and make method calls against the class. I'll post a full solution for anyone who hasn't quite followed my last comments when I get a moment. Thanks again Brian!

@Hooligancat Can you post your full solution? I have the same problem: I would like to pass the class instance into the clientContext but I dont know how.

@FR6 - I haven't touched this code in a while, but I will take a dig through and see if I can find it for you and post the entire code. Stay tuned...

@FR6 - I know its been a while, but I never did manage to dig out this code. We canned the project and I had dumped the code base. Sorry :-( If I come across it I will still post it even though it's probably a little late for you.

objective c - Displaying file copy progress using FSCopyObjectAsync - ...

objective-c cocoa carbon nsfilemanager nsprogressindicator