Skip to content

Instantly share code, notes, and snippets.

View d-kahara's full-sized avatar
:octocat:
Talk is cheap, show me the code 🙂

David Kahara d-kahara

:octocat:
Talk is cheap, show me the code 🙂
  • SIEAL
  • Nairobi, Kenya
View GitHub Profile
import psycopg2
def get_data():
try:
# Establish a connection to the database
connection = psycopg2.connect(
user = "your_username",
password = "your_password",
host = "127.0.0.1", # replace with your host if different
port = "5432", # replace with your port if different
@d-kahara
d-kahara / gist:64002d6e774d19bdba0e67380f97c4e5
Created July 27, 2022 06:29
Install Code deploy agent on Ubuntu 22.04 LTS
!/bin/bash
sudo apt-get update
sudo apt-get install ruby-full ruby-webrick wget -y
cd /tmp
wget https://aws-codedeploy-us-east-1.s3.us-east-1.amazonaws.com/releases/codedeploy-agent_1.3.2-1902_all.deb
@d-kahara
d-kahara / create-superuser.py
Created April 22, 2020 12:07 — forked from c00kiemon5ter/create-superuser.py
Extend Django's management createsuperuser command to allow non-interactive creation of a superuser with a password.
"""
Extend createsuperuser command to allow non-interactive creation of a
superuser with a password.
Instructions:
mkdir -p path-to-your-app/management/commands/
touch path-to-your-app/management/__init__.py
touch path-to-your-app/management/commands/__init__.py
#!/bin/bash
wget https://vscode-update.azurewebsites.net/latest/linux-deb-x64/stable -O /tmp/code_latest_amd64.deb
sudo dpkg -i /tmp/code_latest_amd64.deb
@d-kahara
d-kahara / test.ipynb
Created July 5, 2019 14:23
Jupyter Notebook tutorial
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@d-kahara
d-kahara / postgres-cheatsheet.md
Created December 30, 2018 20:16 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h or --help depending on your psql version):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
@d-kahara
d-kahara / test_profile.py
Created December 20, 2018 06:30
This Gist showcases a unit test in Django
"""
Gist handles testting a user model
using django
"""
from django.test import TestCase
# import the user model
from users.models import User
class UserTestCase(TestCase):
@d-kahara
d-kahara / SortedListAdapter.java
Created November 27, 2017 07:08 — forked from xaverkapeller/SortedListAdapter.java
Implementation of a RecyclverView Adapter base class which uses a SortedList internally
import android.content.Context;
import android.support.v7.util.SortedList;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;