Skip to content

Instantly share code, notes, and snippets.

@glacjay
glacjay / tun-ping-linux.py
Created September 18, 2010 04:49
Reading/writing Linux's TUN/TAP device using Python.
import fcntl
import os
import struct
import subprocess
# Some constants used to ioctl the device file. I got them by a simple C
# program.
TUNSETIFF = 0x400454ca
TUNSETOWNER = TUNSETIFF + 2
@christeredvartsen
christeredvartsen / esSetup.sh
Created June 26, 2012 07:15
Setup elasticsearch on CentOS
#!/bin/bash
# Script used to setup elasticsearch. Can be run as a regular user (needs sudo)
ES_USER="elasticsearch"
ES_GROUP="$ES_USER"
ES_HOME="/usr/local/share/elasticsearch"
ES_CLUSTER="clustername"
ES_DATA_PATH="/var/data/elasticsearch"
ES_LOG_PATH="/var/log/elasticsearch"
ES_HEAP_SIZE=1024
package main
import (
"flag"
"fmt"
"github.com/miekg/dns"
"os"
)
var (
@vinoski
vinoski / sws.erl
Last active January 12, 2024 14:59
An example of a very simple HTTP 1.0 web server in Erlang.
%% Simple web server.
-module(sws).
-author('Steve Vinoski <vinoski@ieee.org>').
-export([start/1, start/2]).
%% start/1 takes a handler function and starts the web server on port 8000.
%% start/2 takes a handler function and a port number. The handler function
%% takes two arguments: a TCP socket and request data. The request data is
%% a property list indicating the invoked HTTP method, the target URI, the
package main
import (
"io"
"net"
"os"
"fmt"
"strings"
"syscall"
"unsafe"
@markhuge
markhuge / README.md
Last active March 25, 2016 12:57
Fix failing node deployments on AWS Elastic Beanstalk

Fix failing node deployments on AWS Elastic Beanstalk

Elastic beanstalk runs npm install with a system user that has no homedir. During the npm install step, it's expecting a $HOME env variable for the npm cache (which doesn't exist). add this file to your project's .ebextensions directory to have it use root's homedir as a temporary path.

This workaround was provided by AWS support, but it doesn't appear to be documented anywhere. Determining root cause on this was a massive pain in the ass. Sharing this so others don't need to feel the pain.

ruby doctor.rb
/usr/bin/ruby1.8 (1.8.6)
OpenSSL 0.9.8g 19 Oct 2007: /usr/lib/ssl
SSL_CERT_DIR=""
SSL_CERT_FILE=""
HEAD https://status.github.com:443
OpenSSL::SSL::SSLError: certificate verify failed
The server presented a certificate that could not be verified:

Create an AMI using Packer

What is Packer?

Packer is a tool from Hashicorp that allows you to create machine images in a variety of formats from a single spec file. This can be a very powerful thing when you want to automate the deployment of applications to a variety (or even just more than one, really) platforms.

In our case, we want to deploy an application to VMware and AWS, and soon to Docker. Doing that with a single spec file gives us

  • platforms that are consistent, even if they're different
@adamveld12
adamveld12 / MersennePrimeRandom.cs
Last active March 15, 2022 01:27
Mersenne prime random number generator in C#
/// <summary>
/// Implementation of Mersenne Twister random number generator
/// </summary>
public class MersennePrimeRandom
{
private readonly uint[] _matrix = new uint[624];
private int _index = 0;
public MersennePrimeRandom() : this((uint)(0xFFFFFFFF & DateTime.Now.Ticks)) { }