Skip to content

Instantly share code, notes, and snippets.

@suhailvs
suhailvs / gist:6837260
Created October 5, 2013 06:02
restricting submit per 4seconds.
<form method='post' onsubmit="return validateFormOnSubmit(this)" action=''>
....
<input type="submit" value="ok">
</form>
<script>
var allowSubmit = true;
function validateFormOnSubmit(theForm) {
//prevent multiple submit by restricting submit per 4seconds
if (!allowSubmit){
from django.forms import EmailField
from django.core.exceptions import ValidationError
def isEmailAddressValid( email ):
try:
EmailField().clean(email)
return True
except ValidationError:
return False
@suhailvs
suhailvs / Openshift27.md
Last active August 29, 2015 13:56
Openshift python -2.7, django-1.6 example

Steps to create in OPENSHIFT

  1. Create a Python27 app in Openshift

create a python2.7 application in openshift

if you still don't uploaded the ssh publickey to openshift, then doit:

Much nicer solution can be used for any stackexchange sites::: First, go to stackoverflow.com(or any other stackexchange sites) then define this in your Javascript console(Press F12):

function minec(){ 
  $.getJSON('/unicoin/rock',function(data) {
    setTimeout(function(){
      $.post('/unicoin/mine?rock='+data.rock,{fkey:StackExchange.options.user.fkey})
      .done(function( data ) {
        console.log(data);

});

@suhailvs
suhailvs / vim.md
Created November 22, 2014 03:12
VIM COMMANDS

Move

  • h - <-- ,j - down, k - up, l - -->.
  • w - next word, e - end, b - beginning,
  • 5w - 5 words, ,5h - 5 left,
  • 0 - move to beginning of the line, , $(end to the line)
  • gg - move to beggining of file, ,G - end, , 8G - move to 8th line,

Find

@suhailvs
suhailvs / digitalocean.md
Last active September 25, 2017 05:55
How to Run Django with mod_wsgi and Apache with a virtualenv

guide

0. ssh into digitalocean

ssh root@104.131.108.244

1. update and install

install apache, git,mod-wsgi,mysql and some python packages such as pip,virtualenv and python-dev

@suhailvs
suhailvs / nginx.md
Created December 15, 2014 23:39
Deploy Django on gevent with nginx

create a file /etc/nginx/conf.d/virtual.conf

#
# A virtual host using mix of IP-, name-, and port-based configuration
#

server {
    listen       8080;
    server_name  chat.djangoer.com;

Create thumbnails for an ImageField in django

# -*- encoding: utf-8 -*-
"""
django-thumbs by Antonio Melé
http://django.es
"""
from django.db.models import ImageField
from django.db.models.fields.files import ImageFieldFile

from PIL import Image

@suhailvs
suhailvs / terminal_commands.md
Last active August 29, 2015 14:12
Terminal Commands

to kill all process:

killall -9 <name>

to copy file to server:

scp <filename> root@djangoer.com:

to get disk usage:

@suhailvs
suhailvs / internet_usage.md
Created December 31, 2014 02:17
How to monitor internet usage?

Install

$ apt-get install vnstat

Usage

To create the cron job simply run this command

$ vnstat -u -i eth0