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 / .htaccess
Created November 2, 2014 07:45
redirect ANY naked domains to www.domain.tld
## This is to allow all incoming naked domains to be rewritten as www.domain.tld
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
@gnilchee
gnilchee / .htaccess
Created November 4, 2014 11:31
redirect only a certain naked domain to www, it will ignore subdomains
RewriteEngine ON
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
@gnilchee
gnilchee / ip.php
Created November 7, 2014 16:49
php code to obtain and display requestor's public ip address
<?php echo $_SERVER["REMOTE_ADDR"];echo "\r\n"; ?>
@gnilchee
gnilchee / lamp.pp
Last active August 29, 2015 14:10
puppet manifest ensure vital lamp components installed.
if versioncmp($::puppetversion,'3.7.3') >= 0 {
$allow_virtual_packages = hiera('allow_virtual_packages',false)
Package {
allow_virtual => $allow_virtual_packages,
}
}
node 'node_name' {
@gnilchee
gnilchee / service.pp
Last active August 29, 2015 14:10
puppet manifest ensuring all lamp components are running and enabled
if versioncmp($::puppetversion,'3.7.3') >= 0 {
$allow_virtual_packages = hiera('allow_virtual_packages',false)
Package {
allow_virtual => $allow_virtual_packages,
}
}
node 'node_name' {
@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:
@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 / 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 / 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_multithread.py
Last active March 11, 2022 19:51
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