Skip to content

Instantly share code, notes, and snippets.

View mayuroks's full-sized avatar

Mayur Rokade mayuroks

View GitHub Profile
@mayuroks
mayuroks / aap.js
Created February 6, 2014 00:49
Redis express
var http = require('http'), express = require('express'), redis = require('redis'), RedisStore = require('connect-redis')(express); var redisClient = redis.createClient( 17969, '<redacted>.garantiadata.com', { auth_pass: '<redacted>' } ); var app = express(); app.use(express.cookieParser('pure cat flight grass')); app.use(express.session({ store: new RedisStore({ client: redisClient }) })); app.use(express.urlencoded()); app.use(app.router); app.get('/', function(req, res){ var html = ''; if(req.session.name) html += '<p>Welcome, ' + req.session.name + '.</p>'; html += '<form method="POST"><p>Name: ' + '<input type="text" name="name"> ' + '<input type="submit"></p></form>'; res.send(html); }); app.post('/', function(req, res){ req.session.name = req.body.name; res.redirect('/'); }); http.createServer(app).listen(3000,function(){ console.log('listening on 3000'); });
I'm using a free Redis account from Garantia Data, not that that should make a difference. Do you spot any differences between what I'm doing an
#! /usr/bin/bash
xrandr --newmode "1904x950_60.00" 149.25 1904 2016 2216 2528 950 953 963 986 -hsync +vsync
xrandr --addmode VBOX0 "1904x950_60.00"
@mayuroks
mayuroks / bashrc
Created March 5, 2014 19:59
bashrc
PS1="\[\e[1;36m\]\u\[\e[0m\]\[\e[1;37m\]|\[\e[1;31m\]\h \[\e[1;32m\][\W \$?]: $ \[\e[0m\]"
alias subt='~/Downloads/Sublime\ Text\ 2/sublime_text'
WORK_HOME='~/.venvs'
source /usr/local/bin/virtualenvwrapper.sh
source /usr/local/rvm/scripts/rvm
export TERM="xterm-256color"

Rails ActiveRecord (association) - Cheatsheet

http://guides.rubyonrails.org/association_basics.html

Types of associations

  • belongs_to : TABLE_NAME
  • has_one : TABLE_NAME [:through => :TABLE_NAME]
  • has_many : TABLE_NAME [:through => :TABLE_NAME]
  • has_and_belongs_to_many : TABLE_NAME [:join_table => :TABLE_NAME]
def main():
StNumber, StMark = input('Enter student number and student mark separated by a comma')
StNumber = StNumber.upper()
if len(StNumber)==9 and StNumber[0:6].isalpha() and StNumber[6:].isdigit():
with open("output.txt", "w") as f:
f.write(StNumber + "," + StMark + "\n")
else:
print("Invalid student number")
@mayuroks
mayuroks / dabblet.css
Created September 8, 2012 19:22
The first commented line is your dabblet’s title
/**
* The first commented line is your dabblet’s title
*/
@charset "UTF-8";
/* CSS Document */
.span2{
height: 30px;
width: 150px;
}
@mayuroks
mayuroks / dabblet.css
Created September 8, 2012 19:28
The first commented line is your dabblet’s title
/**
* The first commented line is your dabblet’s title
*/
@charset "UTF-8";
/* CSS Document */
.span2{
height: 30px;
width: 150px;
}
@mayuroks
mayuroks / dabblet.css
Created September 8, 2012 19:27
The first commented line is your dabblet’s title
/**
* The first commented line is your dabblet’s title
*/
@charset "UTF-8";
/* CSS Document */
.span2{
height: 30px;
width: 150px;
}
@mayuroks
mayuroks / hello.py
Created June 14, 2013 03:20
python 3 Hello World
from requests import get
import sys
def do_sth:
print('Hello World !')
class VideoList(ListView):
model = Video
paginate_by = 15
template_name = "vid_index.html"
context_object_name = "vid_list"
def get_context_data(self, **kwargs):
context = super(VideoDetail, self).get_context_data(**kwargs)
context['big_video'] = Video.objects.filter(id=1)
# Iterate over vid_list in templates for