Skip to content

Instantly share code, notes, and snippets.

View cuibonobo's full-sized avatar

Jen Garcia cuibonobo

View GitHub Profile
@cuibonobo
cuibonobo / sidebar
Created July 10, 2016 21:48 — forked from shilman/sidebar
proxy_cache_path /var/cache/nginx/sidebar levels=1:2 keys_zone=SIDEBAR:10m inactive=24h max_size=1g;
upstream sidebar {
ip_hash;
server xxx.xxx.xx.xxx:80;
server yyy.yyy.yy.yyy:80;
}
server {
@cuibonobo
cuibonobo / template_engine.js
Created May 10, 2016 21:40
A very simple template engine for Javascript.
/*
A very (*very*) simple templating function taken from
http://krasimirtsonev.com/blog/article/Javascript-template-engine-in-just-20-line
The full function includes support for if statements, for loops and other
control structures, but I stripped those out to keep it as simple and fast as
possible.
You use it like this:
@cuibonobo
cuibonobo / solo-asana.css
Last active January 4, 2016 18:14
Stylesheet to use Asana by yourself: eliminates 'team people' from the sidebar and hides the team page and calendar links.
/*
These are known to work in [Stylebot][1] for Google Chrome and [Stylish][2]
for Safari.
[1]: https://github.com/ankit/stylebot
[2]: http://sobolev.us/stylish/
*/
div.team-people, a.team-page-link, a.team-calendar-link, div.team-browser-and-arrow {
/* If these items were collapsible or smaller I would have left them alone,
@cuibonobo
cuibonobo / Vagrantfile
Created October 22, 2015 01:28
Saving logs to MongoDB with Syslog NG
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "box-cutter/centos67"
config.vm.provision :shell, path: "bootstrap.sh"
end
@cuibonobo
cuibonobo / telnet_chat.py
Created September 28, 2015 22:16
Access this with `telnet 127.0.0.1 56789`
import socket
RECV_BUFFER = 1024
BIND_ADDR = ""
PORT = 56789
conn_inputs = []
conn_outputs = []
listener = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
@cuibonobo
cuibonobo / thumbnail_server.md
Created August 16, 2015 16:32
Thumbnail server thoughts

I briefly entertained the idea of mixing thumbnails and original data in the same directory structure, but the truth is that thumbnails have very different needs and applications and, by their very nature, they are disposable data, so they should be handled separately.

@cuibonobo
cuibonobo / pyvmomi_demo.py
Created August 12, 2015 21:27
Grab the UUID from an ESXi machine using PyVmomi
import ssl
import requests
import atexit
from pyVim import connect
from pyVmomi import vim
# Be sure to set these first
# IP_ADDRESS = ''
# USER = ''
@cuibonobo
cuibonobo / create_user.sh
Created August 11, 2015 14:19
Create a user from the command line on Mac OS X
#!/bin/bash
# This must be run as root. Needs to ask for password interactively and get the next unique
# user ID automatically, but you get the idea.
USERNAME='username'
USER_ID=510
DISPLAY_NAME='User Name'
PASSWORD='password'
@cuibonobo
cuibonobo / python-daemons.md
Last active March 25, 2016 07:57
Running daemons in Python

Once a daemon is running, I need some way of communicating with it. That's where Pyro comes in. (I briefly considered running an HTTP server, but the HTTP protocol was designed to handle resources, not remote procedure calls (RPC). Plus, the overhead of an HTTP server, URL handling, and JSON parsing compared to a lightweight Pyro daemon was too much to justify if my plans were to only interact with the daemon over SSH.)

Example Pyro daemon

Example taken from http://stackoverflow.com/questions/24461167/how-can-i-cleanly-exit-a-pyro-daemon-by-client-request. (My test did not demonstrate the hangs that the OP was experiencing.)

server.py:

@cuibonobo
cuibonobo / idle_time.sh
Last active August 29, 2015 14:27
How to detect that a person has been idle on Mac OS X
#!/bin/sh
# Output is given in seconds. Taken from http://stackoverflow.com/a/8659356 and *originally* from
# http://hints.macworld.com/article.php?story=20040330161158532 (posted in 2004!!)
echo $((`ioreg -c IOHIDSystem | sed -e '/HIDIdleTime/ !{ d' -e 't' -e '}' -e 's/.* = //g' -e 'q'` / 1000000000))