Skip to content

renefs/codesnug

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Codesnug

License Python Django

Codesnug is a web-based repository for storing, organizing, and sharing reusable code snippets. Originally developed as a Master's Degree Final Project, it provides developers with a platform to manage their code knowledge base efficiently.

Features

  • Code Snippets Management: Store and organize code snippets with syntax highlighting for 80+ programming languages
  • Goals: Group related snippets into "Goals" for better organization
  • Workspaces: Create workspaces to organize goals by project or topic
  • Tags: Categorize and filter snippets using custom tags
  • User Groups: Share workspaces with team members with different permission levels (Admin, Editor, Subscriber)
  • Full-Text Search: Powered by Haystack and Whoosh for fast code discovery
  • REST API: Access your data programmatically via RESTful endpoints
  • User Authentication: Complete registration system with email verification
  • Data Export: Download your snippets and goals in various formats
  • Internationalization: Available in English and Spanish
  • SSL Security: Built-in HTTPS support with security best practices

Supported Languages

Codesnug supports syntax highlighting for 80+ programming languages including:

Python, JavaScript, Java, C/C++, C#, Ruby, Go, Rust, PHP, TypeScript, Swift, Kotlin, Scala, Haskell, SQL, HTML, CSS, SASS/SCSS, Markdown, JSON, XML, YAML, Shell/Bash, and many more.

Tech Stack

  • Backend: Django 1.6
  • Database: PostgreSQL
  • Search Engine: Haystack with Whoosh backend
  • API: Django REST Framework
  • Frontend: Bootstrap (Bootflat theme)
  • Authentication: django-registration
  • Code Editor: ACE Editor

Requirements

  • Python 2.7
  • PostgreSQL
  • pip

Installation

1. Clone the Repository

git clone https://github.com/renefs/codesnug.git
cd codesnug

2. Create a Virtual Environment

virtualenv venv
source venv/bin/activate

3. Install Dependencies

pip install -r requirements.txt

Note: If requirements.txt is not present, install the following packages:

pip install django==1.6 psycopg2 south django-registration django-bootstrap-breadcrumbs django-widget-tweaks django-uuidfield django-ajax-selectable django-awesome-avatar django-cookielaw django-braces django-recaptcha django-haystack whoosh djangorestframework django-sslserver djangosecure sslify

4. Configure the Database

Create a PostgreSQL database:

createdb codesnug

Update the database settings in codesnug_project/codesnug/settings.py:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'codesnug',
        'USER': 'your_username',
        'PASSWORD': 'your_password',
        'HOST': 'localhost',
        'PORT': '5432',
    }
}

5. Run Migrations

cd codesnug_project
python manage.py syncdb
python manage.py migrate

6. Build the Search Index

python manage.py rebuild_index

7. Run the Development Server

For HTTPS (recommended):

python manage.py runsslserver

Or for HTTP (development only):

python manage.py runserver

Visit https://localhost:8000 (or http://localhost:8000 for HTTP) in your browser.

Project Structure

codesnug_project/
├── codesnug/
│   ├── api/            # REST API endpoints
│   ├── goals/          # Goals, Snippets, Workspaces, Tags
│   ├── search/         # Search functionality (Haystack)
│   ├── users/          # User management and authentication
│   ├── templates/      # HTML templates
│   ├── templatetags/   # Custom template filters
│   ├── settings.py     # Django settings
│   ├── urls.py         # URL routing
│   └── views.py        # Main views
├── locale/             # Internationalization files (en, es)
├── static/             # Static assets (CSS, JS, images)
└── manage.py           # Django management script

API Endpoints

Codesnug provides a RESTful API for programmatic access:

Endpoint Method Description
/api/goals/ GET List all goals
/api/goals/<uuid> GET Get goal details
/api/snippets/ GET List all snippets
/api/snippets/<uuid> GET Get snippet details
/api/workspaces/ GET List all workspaces
/api/workspaces/<uuid> GET Get workspace details
/api/tags/ GET List all tags
/api/tags/<uuid> GET Get tag details
/api/users/<username> GET Get user details

Authentication: All API endpoints require authentication. Use the browsable API at /api-auth/login/ for session-based authentication.

Configuration

Environment Variables

For production, configure the following in settings.py:

# Security
DEBUG = False
SECRET_KEY = 'your-secret-key'
ALLOWED_HOSTS = ['your-domain.com']

# Email (for registration)
EMAIL_HOST = 'smtp.your-provider.com'
EMAIL_HOST_USER = 'your-email'
EMAIL_HOST_PASSWORD = 'your-password'

# reCAPTCHA
RECAPTCHA_PUBLIC_KEY = 'your-public-key'
RECAPTCHA_PRIVATE_KEY = 'your-private-key'

Workspace Permissions

  • Admin: Full control over workspace
  • Editor: Can add and modify content
  • Subscriber: Read-only access

Running Tests

cd codesnug_project
python manage.py test goals
python manage.py test users
python manage.py test search

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Author

René Fernández - GitHub

Acknowledgments

About

Web-based repository for storing, organizing, and sharing reusable code snippets

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors