Skip to content

Instantly share code, notes, and snippets.

@Boorj
Boorj / excel_trigram_comparison.vb
Created November 6, 2018 13:19
Excel trigram (3 ngram) comparison function
Function preg_replace(text, strPattern As String, strReplace As String)
Dim txt As String: txt = text
Set regEx = CreateObject("VBScript.RegExp")
With regEx
.Global = True
.MultiLine = False
.IgnoreCase = False
.Pattern = strPattern
function getDomain(url) {
return url.match(/:\/\/(.[^/]+)/)[1];
}
$("a[href^='http']").each(function() {
$(this).css({
background: "url(http://www.google.com/s2/u/0/favicons?domain=" + getDomain(this.href) +
") left center no-repeat",
"padding-left": "20px"
});
@Boorj
Boorj / Conf2.xml
Last active July 17, 2020 13:16
Jetbrains IDE (i.e. PhpStorm, WebStorm) config for highlighting Sphinx config files
<filetype binary="false" description="Sphinx.conf" name="Sphinx config file" icon="AllIcons.Nodes.Static">
<highlighting>
<options>
<option name="LINE_COMMENT" value="#" />
<option name="COMMENT_START" value="" />
<option name="COMMENT_END" value="" />
<option name="HEX_PREFIX" value="" />
<option name="NUM_POSTFIXES" value="" />
<option name="HAS_BRACES" value="true" />
</options>
@Boorj
Boorj / gist:db8316887a6fd1f7ca90cea126d39b6a
Created March 25, 2018 08:39
Adding and Removing Classes, with simple cross-browser JavaScript
Adding and Removing Classes, with simple cross-browser JavaScript
The standard JavaScript way to select an element is using document.getElementById("Id"), which is what the following examples use - you can of course obtain elements in other ways, and in the right situation may simply use this instead - however, going into detail on this is beyond the scope of the answer.
To change all classes for an element:
To replace all existing classes with one or more new classes, set the className attribute:
document.getElementById("MyElement").className = "MyClass";
(You can use a space-delimited list to apply multiple classes.)
@Boorj
Boorj / UploadSanitizerProvider.php
Last active December 6, 2017 21:44
Uploaded filename sanitizer for Bolt (updated)
<?php
namespace Bolt\Provider;
use Cocur\Slugify\Slugify;
use Silex\Application;
use Silex\ServiceProviderInterface;
class SanitizerProvider implements ServiceProviderInterface
{
protected $replacement;
@Boorj
Boorj / better_sanitizer.php
Created November 24, 2017 10:49
Proper sanitizing for non-latin symbols in filenames
<?php
$app['upload'] = $app->share(
$app->extend(
'upload',
function (\Sirius\Upload\Handler $uploadHandler) {
$uploadHandler->setSanitizerCallback(
function ($filename) {
$clean_name = $filename;
<?php
namespace MyNewApp\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
use Bolt\Application;
@Boorj
Boorj / CSVImportCommand.php
Created November 23, 2017 12:23 — forked from rossriley/CSVImportCommand.php
Import Content to Bolt from CSV File
<?php
namespace Mysite\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
use Bolt\Application;
<?php
namespace MyApp\Response;
use Symfony\Component\HttpFoundation\Response;
class CsvResponse extends Response
{
protected $data;
@Boorj
Boorj / uploadSanitiser.php
Created November 23, 2017 10:05 — forked from rossriley/uploadSanitiser.php
Bolt: Extending the upload handler with custom sanitiser
$app['upload'] = $app->share(
$app->extend(
'upload',
function ($uploadHandler) {
$uploadHandler->setSanitizerCallback(
function ($filename) {
// Do things with filename string here.
return $filename;
}
);