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 / vim_configs
Last active August 29, 2015 14:17
VIM
" Vim Cheat sheet
" http://vim.rtorr.com/
" If ctrl + s freezes your vim, use this config in .bashrc to disable sending xoff
" stty -ixon
" This command will remove trailing whitespace on save
autocmd BufWritePre *.* :%s/\s\+$//e
" Set line numbers
@bjarneo
bjarneo / ab
Last active August 29, 2015 14:18
a/b javascript
var r = 0,
len = 1000000,
a = 0, b = 0;
while (len--) {
r = Math.floor(Math.random() * 2) + 1;
if (r === 1) {
a++;
} else {
@bjarneo
bjarneo / cache.php
Last active November 30, 2019 04:04
CLI clear cache. Add this file to shell/. Repo: https://github.com/bjarneo/MagentoCacheTool
<?php
/**
* Clear cache CLI style
*
*
* @category Mage
* @package Mage_Shell
* @copyright Copyright (c) 2015 Bjarne Oeverli (http://bjarneo.codes)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
@bjarneo
bjarneo / npm
Created May 21, 2015 18:28
run npm without sudo
sudo chown -R $(whoami) ~/.npm
@bjarneo
bjarneo / Resources
Created May 27, 2015 06:03
Resources
Model + View
http://stackoverflow.com/a/5864000
@bjarneo
bjarneo / test_async
Created June 30, 2015 10:21
Test async. Use this to block.
var stop = new Date().getTime();
while(new Date().getTime() < stop + 10000);
(function(){
function getRandomColor() {
var letters = '0123456789ABCDEF'.split('');
var color = '#';
for (var i = 0; i < 6; i++ ) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
import React from 'react';
import ReactDOM from 'react-dom';
import FeedList from './feed-list';
class Feed extends React.Component {
render() {
return (
<div className="feed-wrapper">
<FeedList />
</div>
// 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();
@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);
}