Skip to content

Instantly share code, notes, and snippets.

View gnilchee's full-sized avatar

Greg Nilchee gnilchee

  • Evernote
  • Woodinville, WA
View GitHub Profile
@gnilchee
gnilchee / passgen.py
Created July 24, 2015 11:47
python 3 password generator
#!/usr/bin/env python3
import string
import random
import sys
if len(sys.argv) != 2:
print("\033[91mUsage:\033[0m", sys.argv[0], "pass_length")
sys.exit(1)
pass_len=int(sys.argv[1])
@gnilchee
gnilchee / http.go
Created July 17, 2015 03:49
Go HTTP Server
package main
import "net/http"
func main() {
// http.Handle is relative to directory where http.go is run from
// http.Dir is relative path from where http.go was executed from
http.Handle("/", http.FileServer(http.Dir("./html")))
http.ListenAndServe(":8080", nil)
}
@gnilchee
gnilchee / getdents.c
Created July 8, 2015 16:01
search a directory more efficiently. Based on http://man7.org/linux/man-pages/man2/getdents.2.html
/* Compile with
* ]$ gcc getdents.c -o getdents
*/
#define _GNU_SOURCE
#include <dirent.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/stat.h>
@gnilchee
gnilchee / virt-install
Last active August 29, 2015 14:23
virt-install cheatsheet
# brand new install with iso
virt-install -n gues_name --os-type=Linux --ram=2048 --vcpus=2 --disk path=/path/to/disk/new_guest_disk.img,size=20 --cdrom=/path/tp/ISOs/new_iso.iso --network bridge:br0 --graphics vnc,listen=0.0.0.0 --noautoconsole
# delete kvm
virsh list --all
virsh undefine guest_name
virsh vol-list --pool Disks # Disks is where I have my disks stored, /path/to/Disks
virsh vol-delete --pool Disks guest_disk.img
# import from existing image
@gnilchee
gnilchee / custom_kernel.sh
Created June 3, 2015 04:02
DigitalOcean Custom Kernel
[root@kern ~]# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
[root@kern ~]# rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
[root@kern ~]# yum --enablerepo=elrepo-kernel install kernel-ml
[root@kern ~]# cd /boot
[root@kern boot]# ls -l
----MAKE NOTE of initramfs-[kern_version].img and vmlinuz-[kern_version] you want to boot from, version must match----
[root@kern ~]# kexec -l /boot/vmlinuz-4.0.4-1.el7.elrepo.x86_64 --initrd=/boot/initramfs-4.0.4-1.el7.elrepo.x86_64.img --command-line="root=/dev/vda1 ro"
[root@kern ~]# reboot
@gnilchee
gnilchee / https_server_multithread.py
Last active July 25, 2025 19:32
Multi-threaded Python 3 HTTPS Server
#!/usr/bin/env python3
import sys, os, socket, ssl
from socketserver import ThreadingMixIn
from http.server import SimpleHTTPRequestHandler, HTTPServer
HOST = socket.gethostname()
class ThreadingSimpleServer(ThreadingMixIn, HTTPServer):
pass
@gnilchee
gnilchee / http_multithreaded.py
Last active March 12, 2024 13:54
Multi-threaded Python3 HTTP Server
#!/usr/bin/env python3
import sys, os, socket
from socketserver import ThreadingMixIn
from http.server import SimpleHTTPRequestHandler, HTTPServer
HOST = socket.gethostname()
class ThreadingSimpleServer(ThreadingMixIn, HTTPServer):
pass
@gnilchee
gnilchee / https_server.py
Last active April 6, 2022 18:08
Simple Single threaded HTTPS (SSL) "Server" using Python 3
#!/usr/bin/env python3
import http.server, socketserver, socket, ssl
PORT = 443
HOST = socket.gethostname()
Handler = http.server.SimpleHTTPRequestHandler
https = socketserver.TCPServer(("0.0.0.0", PORT), Handler)
https.socket = ssl.wrap_socket(https.socket, keyfile='/path/to/keyfile.key', certfile='/path/to/certfile.crt', server_side=True, ssl_version=ssl.PROTOCOL_TLSv1_2, ca_certs=None, do_handshake_on_connect=True, suppress_ragged_eofs=True, ciphers='ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!3DES:!MD5:!PSK')
@gnilchee
gnilchee / pig_latin.py
Created February 22, 2015 09:00
An Different Pig Latin Translator Example
#!/usr/bin/env python2
import time
def pig_latin():
original = raw_input("Give me a word: ")
if len(original) > 0 and original.isalpha():
# print "You originally inputed:", original
low_orig = original.lower()
pig = "ay"
fl = low_orig[0]
@gnilchee
gnilchee / lastofus.py
Last active August 29, 2015 14:15
Kinda like Last of Us, but really just playing with functions
#!/usr/bin/env python2
import time
def joel_or_ellie():
char = raw_input("(J)oel or (E)llie? ").lower()
if char == "joel" or char == "j":
joel_weapons()
elif char == "ellie" or char == "e":
ellie_weapons()
else: