Skip to content

Instantly share code, notes, and snippets.

View bmcculley's full-sized avatar

bmcculley

View GitHub Profile
@bmcculley
bmcculley / et2gNy1MgjD.go
Created September 7, 2019 03:42
Parse a hostname into a slice from a URL https://play.golang.com/p/et2gNy1MgjD
package main
import (
"fmt"
"log"
"net/url"
"strings"
)
func ParseHostname(domain string) []string {
@bmcculley
bmcculley / dns_server.py
Created June 26, 2019 04:43
An example DNS server using twisted.
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.
"""
An example demonstrating how to create a custom DNS server.
The server will calculate the responses to A queries where the name begins with
the word "workstation".
Other queries will be handled by a fallback resolver.
@bmcculley
bmcculley / how-to-copy-aws-rds-to-local.md
Last active May 22, 2019 11:35 — forked from syafiqfaiz/how-to-copy-aws-rds-to-local.md
How to copy production database on AWS RDS(postgresql) to local development database.
  1. Change your database RDS instance security group to allow your machine to access it.
    • Add your ip to the security group to acces the instance via Postgres.
  2. Make a copy of the database using pg_dump
    • $ pg_dump -h <public dns> -U <my username> -f <name of dump file .sql> <name of my database>
    • you will be asked for postgressql password.
    • a dump file(.sql) will be created
  3. Restore that dump file to your local database.
    • but you might need to drop the database and create it first
    • $ psql -U <postgresql username> -d <database name> -f <dump file that you want to restore>
  • the database is restored
strings = {
"s1" : "babad",
"s2" : "cbbd",
"s3" : "",
"s4" : "ac",
"s5" : "abb",
"s6" : "ccd",
"s7" : "adam",
"s8" : "ccc",
"s9" : "caba",
function getFib(position) {
if (position == 0 || position == 1) { return position; }
return getFib(position-1) + getFib(position-2)
}
import java.util.Base64;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
public class EncryptionDecryptionAES {
static Cipher cipher;
public static void main(String[] args) throws Exception {
/*
@bmcculley
bmcculley / completion
Last active October 24, 2018 06:16
Bash autocomplete example
#!/usr/bin/env bash
read -r -d '' TOP_CHOICES <<- EOM
help
list
status
start
stop
kill
configure
@bmcculley
bmcculley / notes.md
Created October 19, 2018 03:52
Fixing importerror cannot import name 'sysconfig' on Ubuntu 18.04

Ubuntu 18.04 Python 3.6.6

ImportError: cannot import name 'sysconfig'

sudo apt install python3-distutils
@bmcculley
bmcculley / example.c
Created September 26, 2018 03:34
Cheat sheet
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
void run() {
system("whoami");
}
int main(int argc, char const *argv[])
@bmcculley
bmcculley / Makefile
Created September 7, 2018 04:59
Calling a c function from assembly example.
all:
gcc -Wall -c hello.c
nasm -f elf64 main.asm
ld main.o hello.o -lc -I /lib64/ld-linux-x86-64.so.2
clean:
rm a.out hello.o main.o