SPSecurity.RunWithElevatedPrivileges

If like me you’re wondering what exactly does SPSecurity.RunWithElevatedPrivileges, this is what I understand of it : SPSecurity.RunWithElevatedPrivileges( () => { using( var newSite = new SPSite( site.Url ) ) { // your stuff } }); Is equivalent to : using( var newSite = new SPSite( site.Url, site.SystemAccount.Token ) ) { // your stuff } So if this is just to open an elevated privilege SPSite, it will be equivalent. But if you do some more complex things, as soon as you load a new SPSite it will open it with the original UserToken. And you lose…

February 22, 2010 · Florent Clairambault

Threads and Sharepoint

When you are using threads on sharepoint, you should take care of some little things : The method used to launch the thread must have the “[STAThread]” attribute, it avoids some huge memory leaks. If you need to use an SPSite from the calling site, you should copy its URL and UserToken to build a new SPSite in the new thread. If you’re not using that “design pattern”, things will get really wrong. And of course you should dispose any sharepoint SPSite (SPWebs come from SPSite) allocated within the thread.

February 20, 2010 · Florent Clairambault

FBSL – Freestyle Basic Script Language

I met Gerôme Guillemin at work (well yes his personal page is totally outdated, he now has long hairs). He invented and supported FBSL, its surrounding development tools and some sample programs. What is quite amazing with this script language is that it only requires a simple 450 KB exe file to run the FSBL scripts and all scripts perform very well (even with the OpenGL samples). The executed programs look like they are some native Win32 applications. I’d say it’s the perfect language for basic style languages addicted programmers. ...

February 18, 2010 · Florent Clairambault

Dirty WordPress APC caching

One or two weeks ago, I made a simple AB benchmarking test on a PHP site I built, it was ok. Then I did the same test on this blog and well… It was freaking slow… On 100 pages with 10 concurrent access, it took 3.5 to 10s to render. Well, I thought I should remove all these plugins I installed to make me and my blog famous (they didn’t perform well). It reduced the generation time by something like 100 ms. ...

February 13, 2010 · Florent Clairambault

WordPress with APC

I updated APC from 3.0 to 3.1 because it totally locked my webserver, it was making it accept HTTP connection but never give any reply. I had some problem accessing the WordPress 3.0 (latest SVN version) admin interface after that upgrade : Fatal error: Call to undefined function wp_dashboard_setup() in /home/sites/clairambault.fr/florent/wp-admin/index.php on line 15 the bad line is : require_once(ABSPATH . 'wp-admin/includes/dashboard.php'); I just found out here it was because I activated APC with the “apc.include_once_override” option set to 1. If you encounter the same problem, just set it to 0 or change the include by something without the ABSPATH constant like for instance : ...

February 12, 2010 · Florent Clairambault

Add a circle overlay to Google Maps API v3

There’s a better alternative : Demo Documentation I only leave the code as it is for people interested in extending the google maps javascript framework. As you might not know, google doesn’t give a circle overlay with its Google Maps API. With the V2 version, someone published it. As it wasn’t available anywhere (at least I could not find it), here is the V3 version of this app. For my little tests, I added some methods : setCenter, setCircleRadius, ...

February 9, 2010 · Florent Clairambault

Redirect port on Linux

Sometimes, you just need to redirect a port on Linux. The solution I could find is to add an entry into xinetd. Here is a sample /etc/xinetd.d file I have, it just redirects the 587 (tcp) port to the 993 port of gmail’s servers. I have to do this because Virgin Mobile France blocks the 993 tcp port. If you’re in the same situation, you can use my server to access you gmail IMAP access. You just have to set the server name to “webingenia.com” and the port to “587”. ...

February 8, 2010 · Florent Clairambault

WordPress supports MultiSites

WordPress now supports MultiSites with its 3.0 version. It’s the current SVN development version. This means you can have one wordpress install for multiple sites. You can see how it works by looking into ms-settings.php. This is quite a good news for anyone willing to manage a community of bloggers. Here is a part of the wp-includes/wp-settings.php file : function wpmu_current_site() { global $wpdb, $current_site, $domain, $path, $sites; if( defined( 'DOMAIN_CURRENT_SITE' ) && defined( 'PATH_CURRENT_SITE' ) ) { $current_site->id = (defined( 'SITE_ID_CURRENT_SITE' ) ? constant('SITE_ID_CURRENT_SITE') : 1); $current_site->domain = DOMAIN_CURRENT_SITE; $current_site->path = $path = PATH_CURRENT_SITE; if( defined( 'BLOGID_CURRENT_SITE' ) ) $current_site->blog_id = BLOGID_CURRENT_SITE; return $current_site; } $current_site = wp_cache_get( "current_site", "site-options" ); if( $current_site ) return $current_site; $wpdb->suppress_errors(); $sites = $wpdb->get_results( "SELECT * FROM $wpdb->site" ); // usually only one site if( count( $sites ) == 1 ) { $current_site = $sites[]; $path = $current_site->path; $current_site->blog_id = $wpdb->get_var( "SELECT blog_id FROM {$wpdb->blogs} WHERE domain='{$current_site->domain}' AND path='{$current_site->path}'" ); $current_site = get_current_site_name( $current_site ); wp_cache_set( "current_site", $current_site, "site-options" ); return $current_site; } $path = substr( $_SERVER[ 'REQUEST_URI' ], , 1 + strpos( $_SERVER[ 'REQUEST_URI' ], '/', 1 ) ); if( is_subdomain_install() ) { $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s", $domain, $path) ); if( $current_site != null ) return $current_site; $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path='/'", $domain) ); if( $current_site != null ) { $path = '/'; return $current_site; } $sitedomain = substr( $domain, 1 + strpos( $domain, '.' ) ); $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s", $sitedomain, $path) ); if( $current_site != null ) return $current_site; $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path='/'", $sitedomain) ); if( $current_site == null && defined( "WP_INSTALLING" ) == false ) { if( count( $sites ) == 1 ) { $current_site = $sites[]; die( "That blog does not exist. Please try http://{$current_site->domain}{$current_site->path}" ); } else { die( "No WPMU site defined on this host. If you are the owner of this site, please check Debugging WPMU for further assistance." ); } } else { $path = '/'; } } else { $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s", $domain, $path) ); if( $current_site != null ) return $current_site; $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path='/'", $domain) ); if( $current_site == null && defined( "WP_INSTALLING" ) == false ) { if( count( $sites ) == 1 ) { $current_site = $sites[]; die( "That blog does not exist. Please try http://{$current_site->domain}{$current_site->path}" ); } else { die( "No WPMU site defined on this host. If you are the owner of this site, please check Debugging WPMU for further assistance." ); } } else { $path = '/'; } } return $current_site; }

January 10, 2010 · Florent Clairambault

ANTS Memory Profiler

Well, I’m speaking about a commercial product again. This time it’s about ANTS Memory Profiler (by Red Gate software, the ones that made .Net reflector). This product will help you identify any .Net memory leak you could have. The truth is, .Net never leaks but you can sometimes make stupid conception mistakes, like forgetting to remove references of some objects (that may contains heavy references themselves). The tool allows you to take snapshots of your running application and compare different snapshots. You can see the difference of memory consumption by some objets or the difference of class instance count. ...

December 30, 2009 · Florent Clairambault

Mono Tools for Visual Studio

I talked about this earlier. The mono tools for Visual Studio is a commercial product that easily enables you to test and port your Windows applications to mono. As I told before this is really a great idea. Because I think Visual Studio is the best IDE and Linux is the best server OS (in my opinion, it’s more efficient and more robust than Windows Server). So, I think it’s the perfect gateway between this two very different (but very close since Mono appeared) environments to achieve greatness. ...

December 29, 2009 · Florent Clairambault