Skip to content

Instantly share code, notes, and snippets.

View navarr's full-sized avatar
🖥️
Magento

Navarr Barnier navarr

🖥️
Magento
View GitHub Profile
@navarr
navarr / gist:6047651
Created July 21, 2013 06:06
Convert a limited set of Markdown to HTML - specifically bold, italics, and links. This is useful in basic chat environments where you do not want block content (images, paragraphs, etc).
String.prototype.markdown2html = function () {
var text = this;
// Bold
text = text.replace(/(\*\*|__)(?=\S)([^\r]*?\S[*_]*)\1/g, "<strong>$2</strong>");
// Italics
text = text.replace(/(\*|_)(?=\S)([^\r]*?\S)\1/g, "<em>$2</em>");
// Auto-detect links and convert them to markdown
text = text.replace(/(\]\()?((https?|ftp|dict):[^'">\s]+)/gi, function($0, $1, $2) { return $1?$0:"[" + $2 + "](" + $2 + ")"});
// Inline Links
text = text.replace(/(\[((?:\[[^\]]*\]|[^\[\]])*)\]\([ \t]*()<?(.*?(?:\(.*?\).*?)?)>?[ \t]*((['"])(.*?)\6[ \t]*)?\))/g, '<a href="$4">$2</a>');
@navarr
navarr / gist:6032142
Last active December 19, 2015 23:08
Ping Bot
// Audio To Play when one of the strings is mentioned
window.pingAudio = new Audio('http://www.soundjay.com/button/sounds/beep-7.mp3');
// Array of strings to notify you on, i.e. ['Navarr','Highlife','Darn'];
window.notifyMeOn = ['ju1cy','mr_darn','admin','help'];
document.sendMessage = function (msg) {
var e = $('#taigachat_message');
var t = e.val();
e.val(msg);
$('#taigachat_send').click();
@navarr
navarr / server.js
Created July 5, 2013 01:41
Minecraft Server Hello World
var mc = require('minecraft-protocol');
var server = mc.createServer({
'online-mode': true,
host: '0.0.0.0',
port: 25565,
});
server.on('login', function(client) {
client.write(0x01, {
entityId: client.id,
levelType: 'default',
@navarr
navarr / gist:5526223
Last active December 17, 2015 01:09
Replace hyperlinks in a textual pattern.
<?php
$description = htmlspecialchars($description);
$matches = array();
preg_match_all('/(\w+:\/\/)?([-\w@:]+\.)+[-\w@:]+(\/\S*)?[^)"\'»”’!?.\s]/', $description, $matches, PREG_SET_ORDER);
$startPos = 0;
foreach ($matches as $match) {
$pattern = $match[0];
if (!isset($match[1]) || !$match[1]) {
$pattern = "http://{$pattern}";
@navarr
navarr / WebServer.php
Created March 24, 2013 07:02
Basic Web Server in PHP
<?php
// Uses https://github.com/Navarr/Sockets
use Navarr\Socket\Socket;
use Navarr\Socket\Server;
class WebServer extends Server
{
protected $clientMap;
/**
* EnjinBot
*
* EnjinBot is a unique JavaScript object that allows for the instantiation
* and manipulation of a bot specifically for the Enjin chat system.
* This is not very useful, as the Enjin chat system has a very slow update
* time, and a very awkward update pattern. It is very likely for messages
* to get lost in the Enjin system, and even more likely to have response times
* upwards of 10 seconds or more due to Enjin's lack of update frequency.
*
@navarr
navarr / gist:4696602
Created February 2, 2013 08:22
DarnBot
document.sendMessage = function(msg) {
var e = $('#chatform .chat-input');
var t = e.val();
e.val(msg);
$('#chatform input[type=submit]').click();
e.val(t);
// Clear Variables?
e = t = null;
};
@navarr
navarr / gist:4615904
Created January 23, 2013 23:49
Unfiltered Chat with Mr_Darn
[17:43:06] <[O] Navarr>hey
[17:43:12] <[O] Navarr>im just here to report that the map is out of date
[17:43:15] <[O] Navarr>and somebody should update it
[17:43:15] <[P] roxie>!politics
[17:43:16] <LuissenTB>as soon as I get out of this snow I'm not coming back D:
[17:43:18] <[Staff] Mr_Darn>i REALLY think i need too.
[17:43:18] <bdawgthegreat>Hello!
[17:43:21] <[P] Scary_Assissin>i think we should stop bottering darn
[17:43:24] <[P] Scary_Assissin>bothering*
[17:43:28] <[O] Navarr>!unmute
@navarr
navarr / gist:4615900
Created January 23, 2013 23:49
Chat with Mr_Darn
[17:43:06] <[O] Navarr>hey
[17:43:12] <[O] Navarr>im just here to report that the map is out of date
[17:43:15] <[O] Navarr>and somebody should update it
[17:43:39] <[Staff] Mr_Darn>Yes Navarr Sir! I'll go do that now!
[17:43:46] <[O] Navarr>owo;;;
[17:43:53] <[Staff] Mr_Darn>oh, wait, thats right, we don't update the map.
[17:43:57] <[O] Navarr>did i just walk in on something?
[17:44:24] <[O] Navarr>Darn: .. why not?
[17:44:41] <[Staff] Mr_Darn>because its redbanhammers map.
[17:44:49] <[O] Navarr>i meant the actual tiles, which are hosted by Shotbow
@navarr
navarr / bot.js
Last active December 11, 2015 02:09
MineZ Chatbot
document.sendMessage = function(msg) {
var e = $('#taigachat_message');
var t = e.val();
e.val(msg);
$('#taigachat_send').click();
e.val(t);
// Clear Variables?
e = t = null;
};