Skip to content

Instantly share code, notes, and snippets.

Avatar

Saket Choudhary saketkc

View GitHub Profile
@saketkc
saketkc / TEST.rb
Created Jul 14, 2011
CodeChef(SPOJ) Problem1 Ruby Solution
View TEST.rb
a=[]
while STDIN.readline.chomp!="42"
a.push($_)
end
a.each { |s| puts s }
@saketkc
saketkc / view.py
Created Dec 6, 2011
Prevent multiple form submission for Django Forms
View view.py
import hashlib
def register(request):
if request.method == 'POST':
request_post = request.POST
registration_form = RegistrationFormUniqueEmail(request_post)
hashstring=hashlib.sha1(str(request.POST.get('csrf_token'))) ## This is going to be unique ! A unique has
if request.session.get('sesionform')!=hashstring:
if registration_form.is_valid():
username = registration_form.cleaned_data['username']
email = registration_form.cleaned_data['email']
View models.py
from django.db import models
from django.forms import ModelForm
from django.contrib.auth.models import User
class ReportTypes(models.Model):
def __unicode__(self):
return self.report_name
report_name = models.CharField(max_length=100)
report_element_json_list = models.TextField(max_length=1000)
report_belongs_to_lab = models.ForeignKey(User)
View forms.py
from django import forms
class NewReportTypeForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
self.report_belongs_to_lab = kwargs.pop('report_belongs_to_lab', None)
super(NewReportTypeForm, self).__init__(*args, **kwargs)
def save(self, commit=True):
instance = super(NewReportTypeForm, self).save(commit=False)
if self.report_belongs_to_lab:
instance.report_belongs_to_lab = self.report_belongs_to_lab
View view.py
def add_new_report_type(request):
if request.method=='POST':
new_report = ReportTypes()
new_report_type_form = NewReportTypeForm(data=request.POST,instance=new_report,report_belongs_to_lab=request.user) #ReportTypes()
if new_report_type_form.is_valid():
new_report_type_form.save()
return HttpResponse("Done")
else :
return HttpResponse("Ditch")
View backend.py
from django.contrib.auth.models import User, check_password
class EmailAuthBackend(object):
"""
Email Authentication Backend
Allows a user to sign in using an email/password pair rather than
a username/password pair.
"""
@saketkc
saketkc / wedding_ivr.php
Created Apr 13, 2012 — forked from kookoolib/wedding_ivr.php
KooKoo Wedding IVR
View wedding_ivr.php
<?php
session_start();
require_once("response.php");//response.php is the kookoo xml preparation class file
$r = new Response();
$r->setFiller("yes");
$recore_wav="update";
if(isset ($_REQUEST['event']) && $_REQUEST['event']== "NewCall" )
{
$_SESSION['caller_number']=$_REQUEST['cid'];
$_SESSION['kookoo_number']=$_REQUEST['called_number'];
@saketkc
saketkc / FileUpload.java
Created May 14, 2012
FileUpload Rest Service
View FileUpload.java
package com.starcamping.boundary.rest;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@saketkc
saketkc / eggipfy.sh
Created May 17, 2012
Eggifying the source code in your repo
View eggipfy.sh
## Installing Virtual Environment and Eggifying your source code for OERPub
Go to your Repo : cd <repo_name>
and then :
virtualenv --no-site-packages .
./bin/easy_install -U ZopeSkel
./bin/paster create --list-templates
./bin/paster create -t nested_namespace <repo_name>
This will create and empty egg for your repo !
@saketkc
saketkc / python_slideshare_api.py
Created Jun 6, 2012
Python file for slideShare API
View python_slideshare_api.py
import urllib, urllib2
import time
import sha
import sys
import mimetools, mimetypes
from cStringIO import StringIO
from BeautifulSoup import BeautifulSoup
class Callable:
def __init__(self, anycallable):