Skip to content

Instantly share code, notes, and snippets.

from sqlalchemy import Table, Column, Integer, String, ForeignKey
from sqlalchemy.orm import mapper
from database import metadata, db_session , Base
from sqlalchemy.ext.declarative import declarative_base
class Team( Base ):
__tablename__='teams'
id = Column (Integer, primary_key = True)
name = Column(String(50))
@sheki
sheki / error.py
Created July 22, 2011 10:07
SQL Alchemy
>>> from models import *
>>> from database import *
>>> from models import *
>>> teamname='ops'
>>> team = db_session.query(Team).filter_by(name=teamname).one()
>>>
>>> packagename="fk-ops-build
File "<stdin>", line 1
packagename="fk-ops-build
^
@sheki
sheki / HTTPApiFilter.scala
Created August 9, 2011 10:20
Scalatra render static content - not working
class HTTPApiFilter extends ScalatraFilter with ScalateSupport
{
get("/api/"){
<html>
<body>
<h1>Hello, world!</h1>
<p>This is the HTTP API. What are you looking for</p>
</body>
@sheki
sheki / gist:1133975
Created August 9, 2011 13:01
RabbitMQ conversation about channels and conversations
shekispeaks: why should I multiplex Multiple AMQP sessions over a single connection and how many concurrent channels can a connections support without any performance degradation.
[2:45pm] shekispeaks: ?
[2:48pm] bob2351: Bob_: yes, all the released code for rabbit, including mgmt is open source
[2:50pm] Bob_: ok, thanks for your help!
[2:50pm] shekispeaks: any help on using RabbitMQ connections?
[2:55pm] aib_007 joined the chat room.
[3:38pm] [diablo] joined the chat room.
[3:57pm] Espen-_- left the chat room. (Excess Flood)
[4:02pm] Espen-_- joined the chat room.
[4:03pm] Espen-_- left the chat room.
@sheki
sheki / Item.java
Created August 29, 2011 16:47
solving TBASE Inheritance in scala
/**
* Autogenerated by Thrift
*
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
*/
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
@sheki
sheki / Example.scala
Created August 29, 2011 17:16
TBase TSerializer Issue.
val item :Item = new Item
val bytes = new TSerializer().serialize(item) //THROWS ABOVE GIVEN ERROR
@sheki
sheki / gist:1203003
Created September 8, 2011 09:21
Bala Ticket Cancellation
i had booked tickets
(02:14:00 IST) SriBalaGGG Nitk: but then i cancelled them
(02:14:06 IST) SriBalaGGG Nitk: after convo was announced
(02:14:09 IST) SriBalaGGG Nitk: fucking
2011-09-27 15:20:58
Full thread dump Java HotSpot(TM) 64-Bit Server VM (20.1-b02-383 mixed mode):
"Attach Listener" daemon prio=9 tid=7fc7a98b8000 nid=0x116622000 waiting on condition [00000000]
java.lang.Thread.State: RUNNABLE
"pool-7-thread-4" prio=5 tid=7fc7a5217800 nid=0x117965000 waiting on condition [117964000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <7df094328> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
import java.util.concurrent.atomic.AtomicInteger;
public class CyclicCounter {
private final int maxVal;
private final AtomicInteger ai = new AtomicInteger(0);
public CyclicCounter(int maxVal) {
this.maxVal = maxVal;
}
object HostPersistence extends Logging {
import scala.collection.JavaConverters._
def allHostNames() : List[String] ={
val template = DBProvider.writeEndPoint().getSimpleJdbcTemplate
val result= template.queryForList("select * from host")
val buffer = new ListBuffer[String]
for (r <- result) {
buffer+=r.get("host")