Skip to content

Instantly share code, notes, and snippets.

View CTimmerman's full-sized avatar

Cees Timmerman CTimmerman

View GitHub Profile
@CTimmerman
CTimmerman / namespace_demo.cpp.md
Last active August 29, 2015 14:20
namespace_demo.cpp

Namespaces keep code contained to prevent confusion and pollution of function signatures.

Here's a complete and documented demo of proper namespace usage:

#include <iostream>
#include <cmath>  // Uses ::log, which would be the log() here if it were not in a namespace, see http://stackoverflow.com/questions/11892976/why-is-my-log-in-the-std-namespace

// Silently overrides std::log
//double log(double d) { return 420; }
@CTimmerman
CTimmerman / mem_perc.py
Created June 4, 2015 14:11
Get and check local and remote (Tomcat) memory usage
"""Checks memory percentage of first process by user name.
2015-06-04 v1.0 by Cees.Timmerman@nospam
Run with `python -m doctest mem_perc.py`.
>>> ps_tomcat = ['ps', 'u', '-U', 'tomcat6']
>>> mem_perc(ps_tomcat) < 20
True
>>> mem_perc(['ssh', 'other.host'] + ps_tomcat) < 20
True
@CTimmerman
CTimmerman / weird_error.log
Last active August 29, 2015 14:22
Meteor Up woes on Windows7/Vagrant/Ubuntu14.04x64/nvm/node
C:\code>meteor create --example todos
C:\code>npm install -g mup
C:\code>cd todos
C:\code\todos>mup init
C:\code\todos>git init
C:\code\todos>git add -A
C:\code\todos>git reset mup.json
C:\code\todos>echo mup.json> .gitignore
C:\code\todos>git commit -m "first commit"
C:\code\todos>npm -v
@CTimmerman
CTimmerman / .htaccess
Last active August 29, 2015 14:24
Redirect permanently all domains to one (HTTPS) - Apache config
RewriteCond %{HTTP_HOST} !^www\.company\.com$ [NC] # nocase
RewriteRule (.*) https://www.company.com/$1 [NE,R=301,L] # noescape, redirect, last
@CTimmerman
CTimmerman / build.log
Created August 5, 2015 08:21
Demeteorized Node on Azure adventures
PS C:\meteor\simple-todos\output> npm install
npm WARN package.json simple-todos@0.0.1 No repository field.
npm WARN package.json simple-todos@0.0.1 No license field.
-
> fibers@1.0.5 install C:\meteor\simple-todos\output\node_modules\fibers
> node ./build.js
child_process: customFds option is deprecated, use stdio instead.
@CTimmerman
CTimmerman / c_style.py
Last active September 8, 2015 00:07
C-style Python
for i in range(3):
#{
if i == 1:
#{
print('Hello ');
print('World!');
#}
#}
@CTimmerman
CTimmerman / wifi_password.bat
Last active September 22, 2015 11:37
Get current WiFi password.
@echo off
rem Run as admin. http://lifehacker.com/find-the-wi-fi-password-for-your-current-network-with-t-1717978747?utm_source=taboola
netsh wlan show profile name=networkname key=clear
pause
@CTimmerman
CTimmerman / find_task.sh
Last active December 22, 2015 09:58
Find task in Linux, excluding apt
grep -Hirn $@ /etc/cron* |grep -v apt
@CTimmerman
CTimmerman / webmon.conf
Last active December 30, 2015 09:52
Simple upstart script
# Save as `/etc/init/webmon.conf` and start your daemon with `sudo service webmon restart`. Output is in `/var/log/upstart/webmon.log`
description "Website monitor"
start on (net-device-up IFACE!=lo) # Start when network is up.
respawn
respawn limit 2 120 # Respawn no more than twice in 120 seconds.
# adduser --home /home/webmon webmon
setuid webmon # Don't run as root.
setgid webmon
chdir /home/webmon # Find uploads etc relatively.
exec /home/webmon/webmon.py # Don't forget the #! and `chmod +x`.
@CTimmerman
CTimmerman / changed
Created January 4, 2016 10:31
Find recent file changes with Bash. Optional arguments: [path] [max age in minutes]
#!/bin/bash
sudo find ${1} -cmin -${2-1} 2>&1 |grep -v /proc/