Skip to content

Instantly share code, notes, and snippets.

@leefish
leefish / validate-currency.js
Last active April 1, 2018 15:40 — forked from lksedor/validate-currency.js
Currency validation method for the jQuery Validation plugin. Decimal place is optional but if included, it requires 2 places. Also, the dollar sign is optional. EDIT: Original gist did not work with $ sign being optional. This gist adds the optional functionality for dollar, euro and pound.
// Validation method for variable currency
$.validator.addMethod("currency", function (value, element) {
return this.optional(element) || /^(?:(\$|€|£))?(\d{1,3}(\,\d{3})*|(\d+))(\.\d{2})?$/.test(value);
}, "Please specify a valid amount");
@leefish
leefish / gist:fb57be591bf9c58b1402
Created October 9, 2015 10:51
HTTPS imgur using sceditor and mybb
/* Lets build a FormData object*/
var fd = new FormData(); // I wrote about it: https://hacks.mozilla.org/2011/01/how-to-develop-a-html5-image-uploader/
fd.append("image", file); // Append the file
var xhr = new XMLHttpRequest(); // Create the XHR (Cross-Domain XHR FTW!!!) Thank you sooooo much imgur.com
xhr.open("POST", "https://api.imgur.com/3/image.json"); // Boooom!
xhr.onload = function() {
var link = JSON.parse(xhr.responseText).data.link;
var linkNoProtocol = link.replace(/^https?\:\/\//i, "");
var code = '[img]' +'https://'+ linkNoProtocol + '[/img]';
$('#message, #signature, textarea[name*="value"]').data('sceditor').insert(code);
@leefish
leefish / trade.css
Last active August 29, 2015 14:25
new stylesheet (final)
.faux-table {
border-radius: 6px;
border: 1px solid hsl(0, 0%, 80%);
padding: 1px;
}
.postbit_buttons.tfoot {
border-bottom-left-radius: 6px;
border-bottom-right-radius: 6px;
min-height: 20px;
}
.select2-container .select2-choice {
height: 34px;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
background-color: #fff;
background-image: none;
background: #fff;
}
$plugins->add_hook('datahandler_pm_insert', 'pm_insert');
$plugins->add_hook('private_do_send_end', 'pm_private_end');
function pm_insert($handler)
{
global $cache;
static $last_uid;
if(!isset($cache->cache['pmcache']))
{
$lateststatus = '';
$query = $db->simple_select('users', 'uid,username,custom_status,custom_status_date,usergroup,displaygroup', 'custom_status != \'\' AND custom_status_date > 0', array('order_by' => 'custom_status_date', 'order_dir' => 'DESC', 'limit' => $mybb->settings['custom_status_latest']));
while ($userstatus = $db->fetch_array($query))
{
$bgcolor = alt_trow();
$userstatus['username'] = format_name($userstatus['username'], $userstatus['usergroup'], $userstatus['displaygroup']);
$userstatus['username'] = '<a href="member.php?action=profile&uid='.intval($userstatus['username']).'"> '.$userstatus['username'].'</a>';
$userstatus['date'] = my_date($mybb->settings['dateformat'], $userstatus['custom_status_date'], '', false).", ".my_date($mybb->settings['timeformat'], $userstatus['custom_status_date']);
$userstatus['status'] = htmlspecialchars_uni($userstatus['custom_status']);
$userstatus['custom_status'] = htmlspecialchars_uni($userstatus['custom_status']);
<!-- Something like this -->
<script>
Modernizr.load({
test: Modernizr.mq('(min-width:400px)'),
yep: '<?php echo $this->baseurl ?>/templates/<?php echo $this->template ?>/js/not-small-screen-stuff.js">',
});
</script>
<!-- Or -->
<script>
@leefish
leefish / marquee.coffee
Created November 10, 2012 18:37 — forked from eric1234/marquee.coffee
<marquee> element lives! - Emulating the behavior of the old marquee element with CoffeeScript/JavaScript
class @Marquee
constructor: (@element, @options={}) ->
# Set defaults
@options['duration'] or= 30
@options['wrapAround'] = true unless 'wrapAround' of @options
@options['direction'] or= 'forward'
# If everything fits don't bother with all this mess
@leefish
leefish / MyXBL_Postbit function.php
Created October 23, 2012 09:13
A simple demonstration of how to cut the number of queries used in a MyBB plugin using the postbit hook
<?php
function myxbl_postbit(&$post) {
global $mybb, $db, $lang, $pids;
$lang->load('myxbl');
static $myxbl;
if (!is_array($myxbl) && $mybb->input['method'] != "quickreply") // Check that the $myxbl variable is not an array. Also ensure we are not using the quick reply - without this check quick replies won't bne posted right as the $pids variable cannot be referenced
{