Skip to content

Instantly share code, notes, and snippets.

@esamson33
esamson33 / merge_sort.py
Created October 16, 2022 02:27
Merge sort in Python
def merge_sort(lst):
"""
Performs in-place sorting using the merge sort algorithm
"""
if len(lst) > 1:
mid = len(lst) // 2
left = lst[:mid]
right = lst[mid:]
merge_sort(left)
@esamson33
esamson33 / create_swap_file.sh
Last active September 16, 2020 07:57
Steps to create a swap file
#!/bin/bash
# Create a swap file with 8GB size
dd if=/dev/zero of=/swapfile bs=8192 count=1048576
mkswap /swapfile
swapon /swapfile
# Add to /etc/fstab
# device target fs options dump pass
# /swapfile none swap sw 0 0
from twisted.application.service import Service
from twisted.protocols.basic import LineReceiver
from twisted.python import log
from twisted.internet.protocol import ClientCreator
from twisted.internet import reactor
class MyProtocol(LineReceiver):
def lineReceived(self, line):
# process bot command
log.msg("recv:", line)
@esamson33
esamson33 / pypy-slackware-howto.txt
Created November 30, 2012 23:31
Setup Pypy on Slackware 14.0 using SBo
Install pypy
1. Go to sbo->python->pypy
2. Download pypy-1.9-linux64.tar.bz2
3. Run pypy.Slackbuild
Install distribute
1. Go to sbo->python-distribute
2. Download distribute-0.6.30.tar.gz
3. Edit distribute.Slackbuild to:
- use pypy instead of python in running setup.py
@esamson33
esamson33 / crypt.js
Created November 20, 2012 09:37
Node.js script to encrypt and decrypt an arbitrary string using 128-bit AES method in CFB mode
/*!
* Node.js script to encrypt and decrypt an arbitrary string using
* 128-bit AES method in CFB mode.
*
*/
// A 16-byte key is required for a 128-bit encryption
var crypto = require('crypto'),
key = new Buffer('sixteen byte key'),
iv = crypto.randomBytes(16),