Skip to content

Instantly share code, notes, and snippets.

View figengungor's full-sized avatar

Figen Güngör figengungor

View GitHub Profile
@figengungor
figengungor / number_of_lines_and_words_of_the_file.py
Created September 29, 2013 13:49
A function that reads a file and returns the number of lines and words in the file as a tuple.
def number_of_lines_and_words_of_the_file(filename):
f = open(filename)
lineNo=0
wordNo=0
for line in f:
wordNo+=len(line.split(" "))
lineNo+=1
return lineNo, wordNo
print number_of_lines_and_words_of_the_file("series.txt")
@figengungor
figengungor / insertionSort.py
Last active December 24, 2015 05:39
A function that takes an arbitrary number of arguments, sorts them using Insertion Sort and returns a list of sorted items.
def insertion_sort(*args):
sList=list(args[:]) //copies args to sList
for index in range(1, len(sList)): //starts from first index not zero
value = sList[index]
i = index-1
while i>=0: //compare values before the current value to the current value
if value<sList[i]:
sList[i+1], sList[i] = sList[i], sList[i+1] //swap if the current value smaller than previous value
i = i-1
else:
@figengungor
figengungor / Rot13.py
Created August 8, 2013 23:16
CS253 Udacity Problem Set 2
import webapp2,cgi
form='''<form method="post">
<textarea name="text">
%(text)s
</textarea>
<input type="submit">
</form>
'''
@figengungor
figengungor / Lesson2FullCode
Created August 8, 2013 19:13
CS253 Udacity
#!/usr/bin/env python
#
# Copyright 2007 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
@figengungor
figengungor / Lesson2FinalCode
Created August 8, 2013 18:55
CS253 Udacity
#!/usr/bin/env python
#
# Copyright 2007 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
@figengungor
figengungor / dragfocus.lua
Created June 14, 2013 20:59
Add focus to drag code so the objects won't interfere with each other while dragging on the screen.
-- create objects
local rect1 = display.newRect( 0, 0, 100, 100 )
local rect2 = display.newRect(300,300, 50,50)
-- touch listener function
local function move(self, event )
if event.phase == "began" then
--set focus on touched object so it won't interfere with other display objects.
display.getCurrentStage():setFocus( self, event.id )
self.isFocus = true
@figengungor
figengungor / drag.lua
Created June 13, 2013 22:16
Dragging a display object in Corona
-- create object
local myObject = display.newRect( 0, 0, 100, 100 )
myObject:setFillColor( 255 )
-- touch listener function
function myObject:touch( event )
if event.phase == "began" then
self.markX = self.x -- store x location of object
self.markY = self.y -- store y location of object
elseif event.phase == "moved" then
@figengungor
figengungor / gist:5774745
Created June 13, 2013 15:41
director scene1
module(..., package.seeall)
local director = require("director")
function new() --all objects and functions should be inside this function
local group = display.newGroup() --create a group object to keep display objects
time = 3 -- count down from 3
--Text will be displayed when time is up!
gogogo = display.newText("Go go go!", 0, 0, "James Fajardo", 100)
@figengungor
figengungor / gist:5774700
Created June 13, 2013 15:36
director main
local director = require("director") --import director
--GLOBALS--
W = display.contentWidth
H = display.contentHeight
--Change Scene--
director: changeScene("scene1") -- go to first scene
@figengungor
figengungor / gist:5774460
Created June 13, 2013 15:09
storyboard main
local storyboard = require("storyboard") --import storyboard
storyboard.purgeOnSceneChange=true --clean scene before moving anothe scene
--GLOBALS--
W=display.contentWidth
H=display.contentHeight
-----------------------------
--Change scene--
storyboard.gotoScene("scene1") --go to first scene