Skip to content

Instantly share code, notes, and snippets.

@Tristor
Tristor / iptables.sh
Last active December 22, 2023 20:19
Simple IPtables script for an OpenVPN server
#!/bin/bash
# Flushing all rules
iptables -F FORWARD
iptables -F INPUT
iptables -F OUTPUT
iptables -X
# Setting default filter policy
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP
@joewiz
joewiz / post-mortem.md
Last active September 3, 2023 11:57
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 *.

  1. * 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.)
  2. Added fs.file-max = 70000 to /etc/sysctl.conf
@espinchi
espinchi / DeviceUtil.java
Last active November 9, 2021 09:36
Check if the running device is an emulator
import android.os.Build;
/**
* Utility methods related to physical devies and emulators.
*/
public class DeviceUtil {
public static boolean isEmulator() {
return Build.FINGERPRINT.startsWith("generic")
|| Build.FINGERPRINT.startsWith("unknown")
@ygotthilf
ygotthilf / jwtRS256.sh
Last active May 6, 2024 08:48
How to generate JWT RS256 key
ssh-keygen -t rsa -b 4096 -m PEM -f jwtRS256.key
# Don't add passphrase
openssl rsa -in jwtRS256.key -pubout -outform PEM -out jwtRS256.key.pub
cat jwtRS256.key
cat jwtRS256.key.pub
@hhcordero
hhcordero / 1_Dockerised_JMeter.md
Last active March 30, 2022 13:44
Dockerized JMeter - A Distributed Load Testing Workflow
@friek
friek / .editrc
Created May 26, 2015 15:31
MySQL client .editrc for backwards compatibility with libreadline
# Ctrl+W to delete the previous word
bind "^W" ed-delete-prev-word
# Ctrl+U to delete the current line contents
bind "^U" vi-kill-line-prev
# Ctrl+R to search the query history
bind "^R" em-inc-search-prev
# Ctrl+Left Arrow to go the previous word
bind "\e[1;5D" vi-prev-word
# Ctrl+Right Arrow to go to the next word
bind "\e[1;5C" vi-next-word
@PaulFurtado
PaulFurtado / usb_reset.py
Last active August 9, 2023 13:46
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
@thinkchip
thinkchip / gist:114f6e8d904ead2bd086
Created August 7, 2014 12:12
EasyMDB RS232 V1.0.2
#
#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
@LeCoupa
LeCoupa / nodejs-cheatsheet.js
Last active April 19, 2024 01:50
Complete Node.js CheatSheet --> UPDATED VERSION --> https://github.com/LeCoupa/awesome-cheatsheets
/* *******************************************************************************************
* THE UPDATED VERSION IS AVAILABLE AT
* https://github.com/LeCoupa/awesome-cheatsheets
* ******************************************************************************************* */
// 0. Synopsis.
// http://nodejs.org/api/synopsis.html
#
#Example of how to use EasyMDB RS232
#Date June/2014
#Version 1.0
#Braulio Chi Salavarria
#Not warranty, for educational purposes
#Thinkchip
import serial
import time