Skip to content

Instantly share code, notes, and snippets.

@Boorj
Boorj / CodeMirror-extra-shortcuts.js
Last active October 19, 2020 17:00 — forked from IamPhytan/custom.js
Codemirror custom Keyboard Shortcuts / JetBrains keymap
// CodeMirror API - https://codemirror.net
/** Duplicate a current line in CodeMirror doc */
function cmDuplicateLine(cm) {
// get a position of a current cursor in a current cell
var currentCursor = cm.doc.getCursor();
// read a content from a line where is the current cursor
var lineContent = cm.doc.getLine(currentCursor.line);
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 / 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.)
<?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;
}
);
@Boorj
Boorj / actions.js
Created October 26, 2016 07:24 — forked from ccorcos/actions.js
export function makePayment(loanId, amount, paymentMethodId) {
return dispatch => {
dispatch(makePaymentSent())
fetch(`/api/loans/${loanId}/payments`, {
headers: new Headers({
'Content-Type': 'application/json',
}),
credentials: 'same-origin',
method: 'POST',
body: JSON.stringify({
@Boorj
Boorj / editor.html
Created September 13, 2016 11:55 — forked from pabluk/editor.html
Markdown Editor
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Markdown Editor</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
@Boorj
Boorj / gist:59e84750736343af91f3
Created December 24, 2015 10:36 — forked from jcsrb/gist:1081548
get avatar from google profiles, facebook, gravatar, twitter, tumblr
function get_avatar_from_service(service, userid, size) {
// this return the url that redirects to the according user image/avatar/profile picture
// implemented services: google profiles, facebook, gravatar, twitter, tumblr, default fallback
// for google use get_avatar_from_service('google', profile-name or user-id , size-in-px )
// for facebook use get_avatar_from_service('facebook', vanity url or user-id , size-in-px or size-as-word )
// for gravatar use get_avatar_from_service('gravatar', md5 hash email@adress, size-in-px )
// for twitter use get_avatar_from_service('twitter', username, size-in-px or size-as-word )
// for tumblr use get_avatar_from_service('tumblr', blog-url, size-in-px )
// everything else will go to the fallback
// google and gravatar scale the avatar to any site, others will guided to the next best version