Skip to content

Instantly share code, notes, and snippets.

View bjarneo's full-sized avatar
🏠
Working from home

bjarneo bjarneo

🏠
Working from home
View GitHub Profile
@bjarneo
bjarneo / twitchbot.js
Last active December 16, 2019 08:06
Basic twitch chat bot
const tmi = require('tmi.js');
// Define configuration options
const opts = {
identity: {
username: 'your_username',
password: 'oauth:your_secret_password' // get the password from https://twitchapps.com/tmi/
},
channels: ['your_channel_name']
};
@bjarneo
bjarneo / mongodb.js
Last active June 11, 2019 06:44
MongoDB
// find date GTE and LT
db.collection.find({createdAt: { $gte: ISODate("2019-04-10T00:00:00Z"), $lt: ISODate("2019-05-10T00:00:00Z") }}).count()
// find and sorted with limit
db.collection.find().sort({_id: -1}).limit(1).pretty()
// Remove from array
db.studios.find().toArray().map(item => item._id).forEach(id => db.studios.update({_id: id}, { $pull: { modules: { type: "commentsModule" } } }));
// Update one property
@bjarneo
bjarneo / Dockerfile
Last active March 2, 2018 13:51
Dockerfile using CreateReactApp, and nginx for handling requests. Docker image size ~17MB.
# The build stage
FROM node:9.5-alpine as builder
WORKDIR /app
COPY package-lock.json .
COPY package.json .
RUN npm i
@bjarneo
bjarneo / config.js
Created March 2, 2018 08:24
client side config
import merge from 'deepmerge';
import delve from 'dlv';
import defaultConfig from './default';
const { REACT_APP_ENV, NODE_ENV } = process.env;
const ENV = REACT_APP_ENV || NODE_ENV;
const config = () => {
try {

Keybase proof

I hereby claim:

  • I am bjarneo on github.
  • I am bjarneo (https://keybase.io/bjarneo) on keybase.
  • I have a public key ASCCxN0Me82nYqYxqHgRtZkKdRNYl64Ohp5Xb4b0IFI58Qo

To claim this, I am signing this object:

module.exports = {
settings: {
runtime: { /* ... */ },
build: { /* ... */ },
},
webpack: (target) => {
const settings = require('roc').getSettings();
console.log(target); // web or node
@bjarneo
bjarneo / iframe.php
Last active June 25, 2016 16:13
iframe shortcode example
// Shortcode usage in the WYSIWYG: [iframe src="https://gist.github.com/bjarneo/65115610d02ac0dd77597464014bddfb"]
function iframe($atts) {
return sprintf(
'<iframe src="%s" />',
$atts['src']
);
}
add_shortcode('iframe', 'iframe');
@bjarneo
bjarneo / Snippets
Last active January 8, 2018 09:14
snippets
# Delete all containers
docker rm $(docker ps -a -q)
# Delete all images
docker rmi -f $(docker images -q)
# Delete all
docker rm -v $(docker ps -a -q -f status=exited)
docker rmi -f $(docker images -f "dangling=true" -q)
@bjarneo
bjarneo / hoki.js
Last active September 18, 2017 16:52
Event emitter in 11 lines of code
const events = {};
function on(event, callback) {
if (!events[event]) {
events[event] = [];
}
events[event].push(callback);
}
// Remove N documents from collection
var idsToRemove = db.collection.find({ "query": "to perform" }).limit(10000).sort({ "_id": -1 }).toArray().map(function(doc) { return doc._id; });
db.collection.remove({ "_id": { $in: idsToRemove }})
// Update
db.collection.update({ "_id": { $set: { "test": "update" } } });
// Get current operations
db.currentOp();