Skip to content

Instantly share code, notes, and snippets.

@brainv
brainv / usb_reset.py
Created January 10, 2018 03:03 — forked from PaulFurtado/usb_reset.py
Reset USB device from python
"""
Example code for resetting the USB port that a Teensy microcontroller is
attached to. There are a lot of situations where a Teensy or Arduino can
end up in a bad state and need resetting, this code is useful for
"""
import os
import fcntl
import subprocess
@brainv
brainv / 1_Dockerised_JMeter.md
Created January 11, 2017 17:51 — forked from hhcordero/1_Dockerised_JMeter.md
Dockerized JMeter - A Distributed Load Testing Workflow
@brainv
brainv / post-mortem.md
Created January 10, 2017 17:32 — forked from joewiz/post-mortem.md
Recovery from nginx "Too many open files" error on Amazon AWS Linux

On Tue Oct 27, 2015, history.state.gov began buckling under load, intermittently issuing 500 errors. Nginx's error log was sprinkled with the following errors:

2015/10/27 21:48:36 [crit] 2475#0: accept4() failed (24: Too many open files) 2015/10/27 21:48:36 [alert] 2475#0: *7163915 socket() failed (24: Too many open files) while connecting to upstream...

An article at http://www.cyberciti.biz/faq/linux-unix-nginx-too-many-open-files/ provided directions that mostly worked. Below are the steps we followed. The steps that diverged from the article's directions are marked with an *.

    • Instead of using su to run ulimit on the nginx account, use ps aux | grep nginx to locate nginx's process IDs. Then query each process's file handle limits using cat /proc/pid/limits (where pid is the process id retrieved from ps). (Note: sudo may be necessary on your system for the cat command here, depending on your system.)
  1. Added fs.file-max = 70000 to /etc/sysctl.conf
  2. Added `nginx soft nofile 1
@brainv
brainv / web-servers.md
Created January 9, 2017 03:57 — forked from willurd/web-servers.md
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
@brainv
brainv / gist:76ae67b161df078ac6425e8736257d13
Created September 3, 2016 16:13 — forked from lttlrck/gist:9628955
rename git branch locally and remotely
git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote
#
#Example of how to use EasyMDB RS232
#Date June/2014
#Version 1.0.2
#Not warranty, for educational purposes
#Thinkchip
#V1.0.1
#dispense coin function
#Level coin changer added
@brainv
brainv / gist:16b1fcbfae6f675884fc
Last active February 17, 2018 01:47
SSH stop in "debug1: SSH2_MSG_KEXINIT sent"
mybaby:~ brainv$ ssh -v 192.168.255.69
OpenSSH_6.7p1 Debian-5, OpenSSL 1.0.1k 8 Jan 2015
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to 192.168.255.69 [192.168.255.69] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa type -1
@brainv
brainv / node_crypto.js
Created November 10, 2015 07:19 — forked from rojan/node_crypto.js
Encrypt in nodejs and decrypt in php or vice versa
var crypto = require('crypto');
var key = 'MySecretKey12345';
var iv = '1234567890123456';
var cipher = crypto.createCipheriv('aes-128-cbc', key, iv);
var decipher = crypto.createDecipheriv('aes-128-cbc', key, iv);
var text = 'plain text';
var encrypted = cipher.update(text, 'utf8', 'binary');
encrypted += cipher.final('binary');
hexVal = new Buffer(encrypted, 'binary');
@brainv
brainv / dd.log
Created October 23, 2015 07:51 — forked from ktheory/dd.log
EC2 EBS-SSD vs instance-store performance on an EBS-optimized m3.2xlarge
# /tmp/test = EBS-SSD
# /mnt/test = instance-store
root@ip-10-0-2-6:~# dd bs=1M count=256 if=/dev/zero of=/tmp/test
256+0 records in
256+0 records out
268435456 bytes (268 MB) copied, 3.26957 s, 82.1 MB/s
root@ip-10-0-2-6:~# dd bs=1M count=256 if=/dev/zero of=/tmp/test
256+0 records in
256+0 records out
@brainv
brainv / strong_pass_helper.php
Created October 17, 2015 12:04
Strong Password helper for php / codeigniter
<?php
/**
* Password Strength Helper
* @packages Helpers
*/
/**
* Password Rules
*
* Check password for complexity and length requirements
*