Skip to content

Instantly share code, notes, and snippets.

@jakoch
Created July 18, 2016 17:49
Show Gist options
  • Save jakoch/12c6e6ee015de4164ce7f14bb2c96332 to your computer and use it in GitHub Desktop.
Save jakoch/12c6e6ee015de4164ce7f14bb2c96332 to your computer and use it in GitHub Desktop.
Highlight multiple chunks of code by using WebWorkers and Highlight.js
<html>
<head>
<title>highlight.js Code by using WebWorkers</title>
<script src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
<!--<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.5.0/styles/github.min.css">-->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.5.0/styles/monokai_sublime.min.css">
<script>
function highlight_code()
{
if (typeof (Worker) === undefined)
return false;
var workerFunction = new Blob(['(' + highlight_worker_function.toString() + ')()'], {type: "text/javascript"});
var localWorkerURL = URL.createObjectURL(workerFunction);
$('div.readme pre, div.readme code').each(function () {
var code = $(this);
var worker = new Worker(localWorkerURL);
//var worker = new Worker('highlightjs-webworker.js');
worker.onmessage = function (event) {
code.html(event.data).addClass('hljs');
}
worker.postMessage(code.text()); // start worker
});
}
function highlight_worker_function() // function body = "highlightjs-webworker.js"
{
onmessage = function (event) {
importScripts('https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.5.0/highlight.min.js');
self.hljs.configure({tabReplace: 4});
var result = self.hljs.highlightAuto(event.data);
postMessage(result.value);
close();
}
}
$(window).on('load', highlight_code);
</script>
</head>
<body>
<div style="width: 840px">
<div class="readme">
<h1>README - justinrainbow/json-schema</h1>
<p>A library for simplifying JSON linting and validation.</p>
<h2><a id="user-content-summary" href="#user-content-summary" rel="nofollow noopener external"></a>Summary</h2>
<p>Uses the <a href="https://packagist.org/packages/justinrainbow/json-schema" rel="nofollow noopener external"><code>justinrainbow/json-schema</code></a> and <a href="https://packagist.org/packages/seld/jsonlint" rel="nofollow noopener external"><code>seld/jsonlint</code></a> libraries to lint and validate JSON data. Also decodes JSON data as to only lint when an error is encountered, minimizing performance impact.</p>
<h2><a id="user-content-installation" href="#user-content-installation" rel="nofollow noopener external"></a>Installation</h2>
<p>Add it to your list of Composer dependencies:</p>
<pre>$ composer require herrera-io/json=1.*</pre>
<h2><a id="user-content-usage" href="#user-content-usage" rel="nofollow noopener external"></a>Usage</h2>
<pre>&lt;?php
use Herrera\Json\Json;
$json = new Json();
$json-&gt;validate($schema, $decoded); // throws Herrera\Json\Exception\JsonException
$data = $json-&gt;decode('{'); // throws Seld\JsonLint\ParsingException</pre>
</div>
<div class="readme">
<h1>README- enkas/bash-tasks</h1>
<p>Shell scripts to update and configure Cent OS</p>
<h2><a id="user-content-example-of-usage" href="#user-content-example-of-usage" rel="nofollow noopener external"></a>Example of usage</h2>
<pre>PATH="./vendor/enkas/bash-tasks/centos"
sh ${PATH}/install.sh httpd
sh ${PATH}/install.sh php
sh ${PATH}/install.sh mysql
sh ${PATH}/install.sh php_dev_tools
sh ${PATH}/install.sh xdebug
...</pre>
<p>Run install.sh --help to list all available arguments</p>
</div>
<div class="readme">
<h1>README - pieter/yaml</h1>
<blockquote>
<p>Now this package support for laravel 5</p>
</blockquote>
<p>This using symfony2 yaml component.</p>
<h2><a id="user-content-installing" href="#user-content-installing" rel="nofollow"></a>installing</h2>
<p>for simple way, try using composer,
add this on your composer.json file in require tag</p>
<pre><code>"pieter/yaml": "dev-master"
</code></pre>
<p>and run from terminal</p>
<pre><code>~/php composer.phar update "pieter/yaml"
</code></pre>
<p>after that,
add this code on <strong>app/config/app.php</strong></p>
<pre><code>array(
'providers' =&gt; array (
other providers,
'Pieter\Yaml\YamlServiceProvider',
),
'aliases' =&gt; array (
other aliases,
'Yaml' =&gt; 'Pieter\Yaml\Facades\Yaml',
)
),
)
</code></pre>
<h2><a id="user-content-config" href="#user-content-config" rel="nofollow"></a>Config</h2>
<p>If you want to create custom config, you can use default config and publish to your project config folder</p>
<pre><code>~/php artisan config:publish pieter/yaml
</code></pre>
<h2><a id="user-content-how-to-use" href="#user-content-how-to-use" rel="nofollow"></a>How to use</h2>
<p>just create in yaml on app/config folder and call from your controller</p>
<pre><code>\Yaml::setFile('[your_file].yml');
return \Yaml::parsing();
</code></pre>
<p>enjoy it !</p>
</div>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment