Skip to content

Instantly share code, notes, and snippets.

@douglas-vaz
douglas-vaz / canvas.html
Created January 9, 2013 08:54
Stretch canvas
<!DOCTYPE html>
<html>
<head>
<title>Test Game</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#gameCanvas').width(window.innerWidth);
$('#gameCanvas').height(window.innerHeight);
});
@douglas-vaz
douglas-vaz / rmconfirm.sh
Created December 16, 2012 14:43
Script that confirms an "rm" call. Add "alias rm=rmconfirm.sh" to ~/.bashrc
#!/bin/bash
inp="No";
echo "Are you SURE you want to delete file(s) in $(pwd)? (No/yes)"
read inp
if [ "$inp" == "yes" ];then
echo "Removing..."
rm $@
else
exit 1
# -*- coding: utf-8 -*-
"""
pygments.console
~~~~~~~~~~~~~~~~
Format colored console output.
:copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@douglas-vaz
douglas-vaz / Turing.py
Created October 14, 2012 13:36
Turing Machine to accept the language {0^m1^m: m >= 1}
print "Enter string"
inp = list(raw_input()) + [' ']
R, L = lambda f:f+1, lambda f:f-1
state, i = 0, 0
machine = [{'0':[1,'X',R], 'Y':[3,'Y',R]}, {'0':[1,'0',R], 'Y':[1,'Y',R], '1':[2,'Y',L]}, {'Y':[2,'Y',L], '0':[2,'0',L], 'X':[0,'X',R]},{'Y':[3,'Y',R], ' ':[4,' ',R]},{}]
while state != 4:
print inp[i],': State = ',state,
@douglas-vaz
douglas-vaz / fcfs.py
Created September 13, 2012 17:46
First Come, Fist Serve Scheduling Algorithm Implementation
#!/usr/bin/python2
print 'Enter number of processes'
n, proc_queue, time = int(raw_input()), [], 0
for i in xrange(n):
proc = []
print 'Enter PID'
proc.append(raw_input())
print 'Enter arrival time'
proc.append(int(raw_input()))
@douglas-vaz
douglas-vaz / sjf.py
Created September 13, 2012 17:44
Shortest Job First Scheduling Algorithm Implementation
#!/usr/bin/python2
print 'Enter number of processes'
n, proc_in, time, proc_queue = int(raw_input()), [], 0, []
for i in xrange(n):
proc = []
print 'Enter PID'
proc.append(raw_input())
print 'Enter arrival time'
proc.append(int(raw_input()))
@douglas-vaz
douglas-vaz / index_cdr.html
Created August 9, 2012 16:39
Cross domain request using callback added to a dynamic script element
<!DOCTYPE html>
<html>
<head>
<!--
Enter your script name in the text box and hit submit. Have a callback in the url and the form data. The callback function should execute.
-->
</head>
<body>
<form>
@douglas-vaz
douglas-vaz / evodd1.asm
Created July 25, 2012 10:03
8086 Assembly count even and odd using RCR
include io.h
data SEGMENT
lf db 0dh,0
cr db 0ah,0
n_prompt db 'Enter size of array',0
el_prompt db 'Enter elements',0
odd_prompt db 'Odd = ',0
even_prompt db 'Even = ',0
n dw 40 dup(?)
@douglas-vaz
douglas-vaz / py_dfa_alc2.py
Created July 23, 2012 18:20
Python DFA to validate strings containing "abac"
#!/usr/bin/python2
print "Enter a string"
str = raw_input()
state = 0
dfa = [{'a':1,'b':0,'c':0},{'b':2,'a':0,'c':0},{'a':3,'b':1,'c':0},{'c':4,'a':2,'b':1},{'a':4,'b':4,'c':4}]
for i in str:
print i,': ',state,' -> ',
state = dfa[state][i]
@douglas-vaz
douglas-vaz / sum_a.asm
Created July 18, 2012 09:48
MASM Sum Average
include io.h
data segment
lf db 0dh,0
cr db 0ah,0
n_prompt db "Enter n:",0
num_prompt db "Enter number",0
res_sum db "Sum = ",0
res_avg db "Average = ",0
n dw 40 DUP(?)