Skip to content

Instantly share code, notes, and snippets.

View ekinertac's full-sized avatar
🥳

Ekin Ertaç ekinertac

🥳
View GitHub Profile
##############################
## POSTGRESQL BACKUP CONFIG ##
##############################
# Optional system user to run backups as. If the user the script is running as doesn't match this
# the script terminates. Leave blank to skip check.
BACKUP_USER=
# Optional hostname to adhere to pg_hba policies. Will default to "localhost" if none specified.
HOSTNAME=
#!/bin/bash
SITE=`pwd`
echo "$SITE"
if [ $1 ]; then
python $SITE/manage.py runserver_plus $1 &
else
python $SITE/manage.py runserver_plus &
fi
@ekinertac
ekinertac / scroll.js
Created September 7, 2013 12:57
Disable body Scrolling on Hover
$('#overflow-scroll').bind('mousewheel DOMMouseScroll', function(e) {
var scrollTo = null;
if (e.type == 'mousewheel') {
scrollTo = (e.originalEvent.wheelDelta * -1);
}
else if (e.type == 'DOMMouseScroll') {
scrollTo = 40 * e.originalEvent.detail;
}
@ekinertac
ekinertac / stringformat.js
Created August 26, 2013 00:11
Javascript String Formatting
/**
* Javascript String Formatting
* Usage:
* >>> "I'm {0} to make him an offer he can't {1}.".format("going", "refuse")
* >>> I'm going to make him an offer he can't refuse.
*/
if (!String.prototype.format) {
String.prototype.format = function() {
var args = arguments;
return this.replace(/{(\d+)}/g, function(match, number) {
@ekinertac
ekinertac / mysql_ann_user.sql
Created August 1, 2013 12:42
mysql add administrative user
DROP USER `ekinertac`@`%`;
FLUSH PRIVILEGES;
SELECT * FROM mysql.user;
GRANT USAGE ON *.* TO `ekinertac`@`%` IDENTIFIED BY 'pass' REQUIRE NONE;
GRANT Select ON *.* TO `ekinertac`@`%`;
GRANT Insert ON *.* TO `ekinertac`@`%`;
GRANT Update ON *.* TO `ekinertac`@`%`;
GRANT Delete ON *.* TO `ekinertac`@`%`;
GRANT Create ON *.* TO `ekinertac`@`%`;
@ekinertac
ekinertac / timedelta.py
Created July 12, 2013 10:56
python time difference
import datetime
import dateutil.relativedelta
dt1 = datetime.datetime.fromtimestamp(123456789) # 1973-11-29 22:33:09
dt2 = datetime.datetime.fromtimestamp(234567890) # 1977-06-07 23:44:50
rd = dateutil.relativedelta.relativedelta (dt2, dt1)
print "%d years, %d months, %d days, %d hours, %d minutes and %d seconds" % (rd.years, rd.months, rd.days, rd.hours, rd.minutes, rd.seconds)
# 3 years, 6 months, 9 days, 1 hours, 11 minutes and 41 seconds
@ekinertac
ekinertac / gist:5954446
Created July 9, 2013 03:22
javascript capitalize
String.prototype.capitalize = function(lower) {
// 'javaSCrIPT'.capitalize(); // -> 'JavaSCrIPT'
// 'javaSCrIPT'.capitalize(true); // -> 'Javascript'
return (lower ? this.toLowerCase() : this).replace(/(?:^|\s)\S/g, function(a) { return a.toUpperCase(); });
};
#!/bin/sh
# http://nathanvangheem.com/news/gunicorn-startup-script-for-django
# Place the script in the file - /etc/init.d/gunicorn or whatever you'd like to call it
# make it executable - chmod +x /etc/init.d/gunicorn
# And finally, wire it up - update-rc.d gunicorn defaults
ADDRESS='127.0.0.1'
PYTHON="/opt/django/bin/python"
GUNICORN="/opt/django/bin/gunicorn_django"
@ekinertac
ekinertac / django_jquery_conflict.html
Created July 7, 2013 20:17
django jquery conflict
<script>
(function($){
jQuery = $.noConflict(true);
})(django.jQuery);
</script>
<script src="/static/js/libs/jquery.js"></script>
@ekinertac
ekinertac / social.py
Last active December 19, 2015 06:49
Social Api Request
from django.http import HttpResponseRedirect, HttpResponse
from django.contrib.auth.models import User
from django.utils import simplejson
from twitter import * # pip install twitter
from facebook import * # pip install requests-facebook
# Manual request
def get_user_details(request):
user = User.objects.get(username=request.user.username)
user = user.social_auth.all()[0]