Skip to content

Instantly share code, notes, and snippets.

from flaskext import wtf
from flaskext.wtf import validators
class PostForm(wtf.Form):
self.languages = ['Java','Python','C','C++','Perl','HTML']
langTuples = [ (str(i) ,self.languages[i])for i in range(0,len(self.languages)) ]
name = wtf.TextField('name', validators=[validators.Required()],)
code = wtf.TextAreaField('code', validators=[validators.Required()])
@sheki
sheki / do.c
Created October 9, 2011 06:20
Meghana Project.
#include<iostream.h>
#include<fstream.h>
#include<string.h>
#include<stdio.h>
struct details
{
char *category;
char *name;
char *phone;
@sheki
sheki / error
Created October 11, 2011 09:08
Squeryl Scala Example
[error] /Users/abhishekk/flipkart/platform/star-command/src/main/scala/flipkart/platform/starcommand/model/Models.scala:34: inferred type arguments [flipkart.platform.starcommand.model.Host,flipkart.platform.starcommand.model.Tag,Nothing] do not conform to method manyToManyRelation's type parameter bounds [L <: org.squeryl.KeyedEntity[_],R <: org.squeryl.KeyedEntity[_],A <: org.squeryl.KeyedEntity[_]]
[error] val hostTags = manyToManyRelation(hosts, tags).via[HostTag]((h, t, ht) => (ht.tagId == t.id, h.id == ht.hostId))
[error] ^
[error] one error found
@sheki
sheki / gist:1280658
Created October 12, 2011 08:34
Debug Log SBT
We couldn’t find that file to show.
def _allHostNames(template: SimpleJdbcTemplate): List[String] = {
val dbResult = template.queryForList("select name from host")
dbResult.flatMap(db => db.getOrElse("name", "").toString)
}
def tagJson(tag: String, json: JValue): String = {
val jsonMap = json.asInstanceOf[JObject].values
val hmm = jsonMap.collect {
case (key: String, value) => (tag + "." + key, value)
}
implicit val formats = net.liftweb.json.DefaultFormats
compact(JsonAST.render(decompose(hmm)))
}
@sheki
sheki / Done.scala
Created October 24, 2011 17:19
Scala Better way to handle Map NULL.
object Host {
def configForHost(host: String): String = {
val resultMap = template.queryForMap("SELECT config FROM host WHERE NAME = ?", host)
resultMap.get("config").toString
}
}
ApiServlet {
get("/config/host/:host") {
function [J, grad] = costFunction(theta, X, y)
%COSTFUNCTION Compute cost and gradient for logistic regression
% J = COSTFUNCTION(theta, X, y) computes the cost of using theta as the
% parameter for logistic regression and the gradient of the cost
% w.r.t. to the parameters.
% Initialize some useful values
m = length(y); % number of training examples
% You need to return the following variables correctly
@sheki
sheki / app.py
Created December 2, 2011 07:06
Flask APplication.
@app.route('/tag/<tag>')
def show_tag(tag):
q = Query(CONFIG_ROOT)
tag_config = q.tag_config(tag, as_yaml=True)
hosts = q.hosts_by_tag(tag)
details = [(h, url_for('show_host', host=h)) for h in hosts]
return render_template("item.html", conf=tag_config, details=details)
@app.route('/api/alltags')
@sheki
sheki / pom.xml
Created December 19, 2011 07:14
fatjar
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2</version>
<configuration>
<finalName>${project.name}</finalName>
<appendAssemblyId>false</appendAssemblyId>
<outputDirectory>${project.build.directory}/package</outputDirectory>