Skip to content

Instantly share code, notes, and snippets.

@rogerbush8
rogerbush8 / install-libreswan-ipsec-vpn-regional-vpc-tunnel-on-aws-ec2_aws_linux_ami_201409
Last active April 26, 2024 07:32
install-libreswan-ipsec-vpn-regional-vpc-tunnel-on-aws-ec2_aws_linux_ami_201409
#!/bin/sh
#
# Shell script for installation and setup of L2TP/IPsec VPN tunnel in site-to-site
# mode (e.g. connecting two inter-regional VPCs). VPN software is libreswan.
#
# This should work on linux systems that are RHEL based.
#
# To install directly from this gist, you can curl the "raw" version and pipe that to
# "bash -s" while also defining the environment variables:
#
@gumblex
gumblex / PathFitter.py
Created April 4, 2015 12:01
Path fitter in Python - An Algorithm for Automatically Fitting Digitized Curves
"""
Ported from Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
http://paperjs.org/
Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
http://scratchdisk.com/ & http://jonathanpuckey.com/
Distributed under the MIT license. See LICENSE file for details.
All rights reserved.
@floer32
floer32 / _socket_toggle.py
Last active December 18, 2019 20:31
Disable the internet in Python. With py.test hooks. (Disable socket.socket.) GREAT for unit testing.
from __future__ import print_function
import socket
import sys
_module = sys.modules[__name__]
def disable_socket():
""" disable socket.socket to disable the Internet. useful in testing.
.. doctest::
@Hackforid
Hackforid / base.py
Created May 13, 2015 08:25
Sqlalchemy use scoped_session in Tornado
# -*- coding: utf-8 -*-
import store
from tools.tor import ThreadRequestContext
class BaseHandler(RequestHandler):
def prepare(self):
store.db()
@brock
brock / psql-with-gzip-cheatsheet.sh
Last active April 1, 2026 12:44
Exporting and Importing Postgres Databases using gzip
# This is just a cheat sheet:
# On production
sudo -u postgres pg_dump database | gzip -9 > database.sql.gz
# On local
scp -C production:~/database.sql.gz
dropdb database && createdb database
gunzip < database.sql.gz | psql database
@jonathanpmartins
jonathanpmartins / install-libsodium.sh
Last active July 28, 2019 03:14
Install Libsodium on Ubuntu 14.04.3 LTS Trusty
#!/bin/bash
sudo add-apt-repository ppa:chris-lea/libsodium;
sudo echo "deb http://ppa.launchpad.net/chris-lea/libsodium/ubuntu trusty main" >> /etc/apt/sources.list;
sudo echo "deb-src http://ppa.launchpad.net/chris-lea/libsodium/ubuntu trusty main" >> /etc/apt/sources.list;
sudo apt-get update && sudo apt-get install libsodium-dev;
@dabeaz
dabeaz / aecho.py
Last active October 17, 2023 03:26
Live-coded examples from my PyCon Brasil 2015 Keynote
# aecho.py
from socket import *
import asyncio
loop = asyncio.get_event_loop()
async def echo_server(address):
sock = socket(AF_INET, SOCK_STREAM)
sock.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
#!/usr/bin/env python
from socket import socket, AF_INET, SOCK_DGRAM, timeout
import hashlib
import time
import struct
from scapy.all import sendp, Ether, IPv6, UDP, Raw
from bitarray import bitarray
IP6 = PUT_TARGET_LINK_LOCAL_IPV6_HERE
@kennethreitz
kennethreitz / auto-sqlalchemy.py
Created February 7, 2016 04:37
Some code for using schemas as your declarative base with SQL-Alchemy, along with support for Celery's forking.
from sqlalchemy import create_engine, MetaData, Table
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
from multiprocessing.util import register_after_fork
Base = declarative_base()
@cguldogan
cguldogan / ExcelOperations.cs
Last active March 29, 2016 13:06
Read Excel in C#
public class ExcelOperations
{
public List<List<string>> Read(string filePath)
{
OleDbConnection conn = new OleDbConnection("Provider = Microsoft.ACE.OLEDB.12.0; Data Source = " + filePath + "; Extended Properties = 'Excel 8.0; HDR=NO'");
OleDbCommand cmd = new OleDbCommand("select * from [Sheet1$]", conn);
conn.Open();
OleDbDataReader dr = cmd.ExecuteReader();