Skip to content

Instantly share code, notes, and snippets.

@acatejr
acatejr / oracle_django_settings.py
Last active August 29, 2015 14:04
Django Oracle DB Settings Example
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.oracle',
'NAME': 'XE', # The instance name
'USER': 'DJORACLE', # User name
'PASSWORD': 'password', # User's password
'HOST': '127.0.0.1', # Hosting server
'PORT': '1521',
},
}
@acatejr
acatejr / sql_server_django_settings.py
Last active August 29, 2015 14:04
Django SQLServer Database Settings Example
DATABASES = {
'default': {
'ENGINE': 'sql_server.pyodbc', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'database_name', # Or path to database file if using sqlite3.
'USER': 'database_user_name', # Not used with sqlite3.
'PASSWORD': 'database_user_password', # Not used with sqlite3.
'HOST': 'LOCALHOST\SQLEXPRESS', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '1433', # Set to empty string for default. Not used with sqlite3.
}
@acatejr
acatejr / random_string.py
Last active August 29, 2015 14:04
Python Random String
import random
import string
string_length = 10
random_string = u''.join(random.choice(string.ascii_letters) for x in range(string_length))
print random_string
@acatejr
acatejr / StringHelpers.groovy
Last active August 29, 2015 14:05
Groovy string cleanup.
/**
* Clean spaces and extraneous characters from a text string.
*
* @params source The source string.
*
* @return The cleaned version of the input string.
*
*/
static def cleanString(String source) {
@acatejr
acatejr / BaseUrl.cs
Created September 24, 2014 16:19
C# Base Url
var baseUrl = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + "/" + Url.Content("~/");
@acatejr
acatejr / WriteToHtml.cs
Last active August 29, 2015 14:09
Changes an html control into an html string equivalent.
private static string WriteToHtml(HtmlContainerControl control)
{
var stringWriter = new StringWriter(new StringBuilder());
var htmlTextWriter = new HtmlTextWriter(stringWriter);
control.RenderControl(htmlTextWriter);
return stringWriter.ToString();
}
@acatejr
acatejr / backends.py
Created November 18, 2014 22:54
Active Directory authentication for Django
from django.contrib.auth.models import User
import ldap
import logging
class ActiveDirectoryBackend:
def __init__(self):
# LDAP server
@acatejr
acatejr / angular_brackets.js
Last active August 29, 2015 14:25
Angular Brackets and CSRF Tokens for Django
// Change the Angular brackets to [[ and ]]
$interpolateProvider.startSymbol('[[').endSymbol(']]');
// Tells the app to use csrf token in views
$httpProvider.defaults.xsrfCookieName = 'csrftoken';
$httpProvider.defaults.xsrfHeaderName = ' X-CSRFToken';
// Stop Angular strip trailing slashes. Angular loves to strip trailing slashes.
// Newer in Angular 3
$resourceProvider.defaults.stripTrailingSlashes = false;
@acatejr
acatejr / enable_svg.py
Last active January 21, 2019 12:31
Rendering svg static files while running Django development server
# The django development server (1.9) does not seem to render svg files. In order to render them these lines
# can be added to the project's settings.py file. This may require restarting the django server and clearing the browser cache.
import mimetypes
mimetypes.add_type("image/svg+xml", ".svg", True)
mimetypes.add_type("image/svg+xml", ".svgz", True)
@acatejr
acatejr / visual_studio_code_tips.md
Created April 14, 2016 14:46
Visual Studio Code Tips

To hide file in the explorer pane File -> Preferences -> User Settings This opens the settings.json file Create like the following entry:

"files.exclude": { "**/*.pyc": true, }

This would prevent all .pyc files from being listed in the Explorer pane tree-veiw.