Skip to content

Instantly share code, notes, and snippets.

@kainlite
kainlite / gist:1902333
Created February 24, 2012 17:45
Mongo Assertion Error With MapReduce
class SomeDocument
include MongoMapper::Document
# Other stuff...
def self.tag_cloud_map
<<-MAP
function() {
this.tags.forEach(function(tag) {
emit(tag, 1);
// kills long running ops in MongoDB (taking seconds as an arg to define "long")
// attempts to be a bit safer than killing all by excluding replication related operations
// and only targeting queries as opposed to commands etc.
killLongRunningOps = function(maxSecsRunning) {
currOp = db.currentOp();
for (oper in currOp.inprog) {
op = currOp.inprog[oper-0];
if (op.secs_running > maxSecsRunning && op.op == "query" && !op.ns.startsWith("local")) {
print("Killing opId: " + op.opid
@kainlite
kainlite / test.html
Created June 18, 2015 02:06
Iframe test
<html>
<body>
<iframe id="contentBody" src="./test1.html">
</iframe>
</body>
</html>
@kainlite
kainlite / content.js
Created June 18, 2015 02:17
Chrome extension
var iframeContentBody = document.getElementById('contentBody');
var innerDocContentBody = iframeContentBody.contentWindow.document;
var iframeRawContent = innerDocContentBody.getElementById('rawContent');
var innerDocRawContent = iframeRawContent.contentWindow.document;
console.log(iframeRawContent.messages);
(function () {
var content = 'setTimeout(function () {' +
'keys = Object.keys(document.getElementById("contentBody").contentDocument.getElementById("rawContent").contentDocument.defaultView.window.messages);'+
'console.log(keys);'+
'}, 5000);';
var s = document.createElement("script");
s.type = "text/javascript";
s.text = content;
document.head.appendChild(s);
@kainlite
kainlite / tmux-copy-mode-osx.md
Created October 31, 2015 23:13 — forked from brendanhay/tmux-copy-mode-osx.md
Tmux, copy-mode, and OSX shenanigans.

Copy, with line wrapping!

If you've been trying to copy/paste text from a multi-pane tmux session with the mouse, you've probably been pretty pissed at the blissful ignorance a terminal application has of the rodent in your hand.

The alternative, which is quote-unqoute native copy/pasting using copy-mode takes a bit to get used to. So this is one solution for copying and pasting lines from a session with correct line wrapping behaviour, albeit keyboard only.

Disclaimer

Since copy-mode has similar concepts of marks, regions, and temp buffers to Emacs .. you'll probably find it straight forward if you're familar with Emacsen. For people using vi-mode in tmux, the same still applies but obviously the default key bindings will differ alot from what I show below.

@kainlite
kainlite / update_curl.sh
Created November 2, 2016 16:23 — forked from fideloper/update_curl.sh
Update curl on Ubuntu 14.04
#! /usr/bin/env bash
# Install any build dependencies needed for curl
sudo apt-get build-dep curl
# Get latest (as of Feb 25, 2016) libcurl
mkdir ~/curl
cd ~/curl
wget http://curl.haxx.se/download/curl-7.50.2.tar.bz2
tar -xvjf curl-7.50.2.tar.bz2
@kainlite
kainlite / check.md
Created February 13, 2017 14:32 — forked from kwilczynski/check.md
Recipe / Role check in Chef

If you want to check whether a node run_list includes a specific role (upon expansion), then you could use role? method on the Node object:

node.role?('name')

Alternatively, you can see whether either would work for you:

node.roles.include?('name')

node.run_list?('role[name]')

@kainlite
kainlite / check.md
Created February 13, 2017 14:32 — forked from kwilczynski/check.md
Recipe / Role check in Chef

If you want to check whether a node run_list includes a specific role (upon expansion), then you could use role? method on the Node object:

node.role?('name')

Alternatively, you can see whether either would work for you:

node.roles.include?('name')

node.run_list?('role[name]')

@kainlite
kainlite / Linux Static IP
Created May 3, 2017 19:25 — forked from fernandoaleman/Linux Static IP
How To Configure Static IP On CentOS 6
## Configure eth0
#
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
NM_CONTROLLED="yes"
ONBOOT=yes
HWADDR=A4:BA:DB:37:F1:04
TYPE=Ethernet
BOOTPROTO=static