Skip to content

Instantly share code, notes, and snippets.

View njb-said's full-sized avatar

njb_said njb-said

  • United Kingdom
View GitHub Profile
@njb-said
njb-said / bot-snippet.js
Created June 15, 2018 23:45
discordbots.org 403 error
if(config.discord.listToken) {
var dblapi = require('dblapi.js');
var dbl = new dblapi(config.discord.listToken, self.bot);
dbl.on('error', (err) => {
logger.error('Error for dblapi.js', err);
bugsnag.notify(err);
});
logger.debug('[BOT] Linked to discordbots.org - updating stats periodically');
} else {
@njb-said
njb-said / card-accent.scss
Created January 18, 2018 21:21
Example of Sass mixins
@mixin accent-colors($position, $direction) {
@if $direction == 'x' {
border-#{$position}-left-radius: 0;
border-#{$position}-right-radius: 0;
} @else {
border-top-#{$position}-radius: 0;
border-bottom-#{$position}-radius: 0;
}
border-#{$position}: 3px solid transparent;
@njb-said
njb-said / helper.js
Created October 10, 2017 16:34
MongoDB pagination
// Terrible code formatting but it works for me
// totalItems = total number of items (across all pages)
// perPage = number of items to show per page
// maxPages = maximum number of pages to show at once
// selectedPage = page currently on
// link = start of link, eg. /search (and then ?page is appended although this code doesn't fully do this)
// reverseSort = if the sortation should be backwards
module.exports.paginate = function(totalItems, perPage, maxPages, selectedPage, link, reverseSort) {
return new Promise(function(resolve, reject) {
@njb-said
njb-said / aggregate-outstanding.js
Last active August 30, 2017 21:54
test for aggregating outstanding orders from mongo shell
db.getCollection('Orders').aggregate([
{
'$match' : { 'products.outstanding' : { $gt: 0 }, 'status' : {$nin:['cancelled', 'dispatched']} }
},
{
'$unwind' : '$products'
},
{
'$group' : {
'_id': '$products._id',
@EventHandler
public void onPing(ProxyPingEvent e) {
ServerPing old = e.getResponse();
ServerPing reply = new ServerPing();
// this playerCount variable is not defined because you can get it yourself.. (or if you use redis/mysql to store online player count)
reply.setPlayers(new ServerPing.Players(playerCount + 1, playerCount, old.getPlayers().getSample()));
reply.setDescription("whatever motd you want");
reply.setFavicon(favicon);
reply.setVersion(old.getVersion());
e.setResponse(reply);

Keybase proof

I hereby claim:

  • I am njb-said on github.
  • I am njb_said (https://keybase.io/njb_said) on keybase.
  • I have a public key whose fingerprint is 2E63 008B EE52 4BDF E8C5 EB7D 8337 28B1 142F D6D5

To claim this, I am signing this object:

@njb-said
njb-said / BukkitHandler.java
Last active August 29, 2015 14:12
A Bukkit handler for uuid-java
package net.mcapi.uuid.handlers;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import net.mcapi.uuid.UUIDAPI;
import net.mcapi.uuid.UUIDHandler;
import net.mcapi.uuid.queries.APIQuery;
import net.mcapi.uuid.utils.UUIDUtils;
public static void tell(CommandSender obj, String msg) {
obj.sendMessage(new TextComponent(color("&7" + msg)));
}