Skip to content

Instantly share code, notes, and snippets.

@harmony7
harmony7 / flattenExceptionBacktrace.php
Created September 29, 2021 06:39 — forked from Thinkscape/flattenExceptionBacktrace.php
Make any PHP Exception serializable by flattening complex values in backtrace.
<?php
function flattenExceptionBacktrace(\Exception $exception) {
$traceProperty = (new \ReflectionClass('Exception'))->getProperty('trace');
$traceProperty->setAccessible(true);
$flatten = function(&$value, $key) {
if ($value instanceof \Closure) {
$closureReflection = new \ReflectionFunction($value);
$value = sprintf(
'(Closure at %s:%s)',
@harmony7
harmony7 / js-grip-stream-fetch.md
Last active May 7, 2020 06:40
Streaming demo with fetch

The following is a demo that uses the fetch API in a browser to subscribe to messages streamed through a GRIP Stream pushed through a sample server that is proxied behind the open-source Pushpin (https://pushpin.org/) server.

To run the demo:

  1. Clone the js-grip repository, then build the commonjs build.
git clone https://github.com/fanout/js-grip
cd js-grip
@harmony7
harmony7 / phpgotcha.md
Last active June 5, 2018 01:25
PHP gotcha

Today i ran into a PHP gotcha, and it had me stumped for a few minutes so i thought i'd share it with you.

$found = false;
foreach($arr as &$item) {
  if ($item['type'] == "mytype") {
    $found = true;
    break;
  }
}
@harmony7
harmony7 / gist:9769831c55a5ff118694
Last active April 7, 2016 04:40
LiveResource Interests
| value | changes | hint | multiplex |
--------+-----------+-----------+-----------+-----------+
plain | no (*1) | yes | no (*2) | no |
wait | yes | yes | no (*3) | yes |
socket | no | no | no | yes |
stream | yes | yes | yes | no |
--------+-----------+-----------+-----------+-----------+
*1 - The current value of a value resource is simply the result of a simple GET to the resource.
@harmony7
harmony7 / gist:4370f34c2aed2409359e
Last active March 4, 2016 08:57
LiveResource updated API
-- VALUE
import { JsonValueInterest, LiveResource } from 'liveresource';
class TimeValueInterest extends JsonValueInterest {
transform(obj) {
return obj.time;
}
}
@harmony7
harmony7 / gist:10621982
Created April 14, 2014 06:43
RouteController transaction fix
diff --git a/src/Orchard.Web/Modules/Upgrade/Controllers/RouteController.cs b/src/Orchard.Web/Modules/Upgrade/Controllers/RouteController.cs
--- a/src/Orchard.Web/Modules/Upgrade/Controllers/RouteController.cs
+++ b/src/Orchard.Web/Modules/Upgrade/Controllers/RouteController.cs
@@ -25,6 +25,7 @@
public class RouteController : Controller {
private readonly IContentDefinitionManager _contentDefinitionManager;
private readonly IOrchardServices _orchardServices;
+ private readonly ITransactionManager _transactionManager;
private readonly ISessionFactoryHolder _sessionFactoryHolder;
private readonly ShellSettings _shellSettings;
@harmony7
harmony7 / gist:6772868
Created October 1, 2013 01:46
Obtain a copy of mercurial
$filename = "tortoisehg-2.9.1-hg-2.7.1-x64.msi"
$source = "http://bitbucket.org/tortoisehg/files/downloads/$filename"
$destination = ".\$filename"
write-host "`nDownloading $source to $destination."
$wc = New-Object System.Net.WebClient
$wc.DownloadFile($source, $destination)