This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Install me via cron: | |
| // MAILTO=somewhere@important.com | |
| // * * * * * /usr/local/bin/php /home/someaccount/loadwatch.php | |
| $fields = explode(' ', file_get_contents('/proc/loadavg')); | |
| $avg = $fields[0]; | |
| $last = @file_get_contents("/home/gps/cpulast.txt"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // This script will spread out your php-cgi fastcgi processes | |
| // evenly over the hyperthreads of your server. | |
| // If your php-cgi process is not /usr/local/bin/php-cgi, | |
| // tweak accordingly. | |
| // | |
| // tom@punkave.com, @boutell, punkave.com |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Are your fastcgi processes spread out evenly over the available hyperthreads on your server? | |
| // This script will tell you. | |
| // | |
| // If your php-cgi process is not /usr/local/bin/php-cgi, tweak accordingly. | |
| // | |
| // In my experience they do tend to distribute pretty well over time, but see also | |
| // assignhyperthreads.php. | |
| // |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Why does this print 'Redirecting' but then send 'You are special' anyway? | |
| function secure(req, res, next) { | |
| if (!req.user) { | |
| console.log('Redirecting'); | |
| req.session.afterLogin = req.url; | |
| res.redirect('/login'); | |
| return; | |
| } | |
| else | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // In my Search entity class: | |
| /** | |
| * @ORM\ManyToOne(targetEntity="Posting", inversedBy="words") | |
| * @ORM\JoinColumn(name="posting_id", referencedColumnName="id", onDelete="cascade") | |
| */ | |
| protected $posting; | |
| // Later, when I want to delete the Search objects for a given Posting entity: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // If there are no matches, getSingleScalarResult will throw an exception | |
| try | |
| { | |
| $this->numResults = $countQb->getQuery()->getSingleScalarResult(); | |
| } catch (\Doctrine\ORM\NoResultException $e) | |
| { | |
| // This happens when zero rows are returned | |
| $this->numResults = 0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| macintosh-5:~ boutell$ set | grep PATH | |
| MANPATH=/opt/local/share/man: | |
| PATH=/Users/boutell/mongodb/bin:/usr/local/bin:.:/Users/boutell/bin:/Users/boutell/.gem/bin:/opt/symfony1.4/data/bin:/opt/local/bin:/opt/local/sbin:/opt/local/apache2/bin:/Users/boutell/personalassistant/festival/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/opt/pktools/bin | |
| macintosh-5:~ boutell$ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| define('NUM_TESTS', 1000); | |
| $before = memory_get_usage(true); | |
| $test = array(); | |
| class Foo | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Extend any Mongoose model that has a unique index on a 'slug' field so that | |
| // if a unique index error occurs on 'slug', a random digit is added to the slug | |
| // and the save operation is retried until it works. This is concurrency-safe even | |
| // if you have lots of inserts going on from multiple machines etc. | |
| // | |
| // By Tom Boutell, tom@punkave.com | |
| // | |
| // NOTE: YOU MUST HAVE THIS PULL REQUEST... https://github.com/LearnBoost/mongoose/pull/837 | |
| // | |
| // (As of this writing that commit is not in LearnBoost/mongoose yet.) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Create a situation where a unique index error will occur. Try to save the | |
| * object again after making the relevant field unique. Then do an update on one of the objects. | |
| * | |
| * Expected behavior: each object after the first saves successfully the second (or third...) time and we wind | |
| * up with ten objects. Actual behavior with current Mongoose: we wind up with one object because the | |
| * isNew flag is never reset to true when an insert fails. Behavior with my pull request: the isNew flag | |
| * is reset if an insert (not an update) fails, allowing save handlers to try again on error after doing things | |
| * like making slugs more unique. | |
| * |