Skip to content

Instantly share code, notes, and snippets.

def count_words(text):
"""Makes a statistic of the words appearing in the text
and returns a dictionary where keys are the words and
values are the number of occurrence of each word."""
words = text.split()
result = {}
for word in words:
if word in result:
result[word] += 1
@gergob
gergob / main.py
Last active March 30, 2019 01:21
from projects_repository import ProjectsRepository
from project import Project
def load_all_items_from_database(repository):
print("Loading all items from database:")
projects = repository.read()
at_least_one_item = False
for p in projects:
at_least_one_item = True
from bson.objectid import ObjectId
class Project(object):
"""A class for storing Project related information"""
def __init__(self, project_id=None, title=None, description=None, price=0.0, assigned_to=None):
if project_id is None:
self._id = ObjectId()
else:
self._id = project_id
from pymongo import MongoClient
from bson.objectid import ObjectId
from project import Project
class ProjectsRepository(object):
""" Repository implementing CRUD operations on projects collection in MongoDB """
def __init__(self):
# initializing the MongoClient, this helps to
# access the MongoDB databases and collections
@gergob
gergob / hello2.html
Created October 23, 2013 18:22
FLOSSzine - Programozás Kezdőkenk - Bevezető - Hello Világ!
<!DOCTYPE html>
<html>
<!-- HTML dokumentum fej része -->
<head>
<!-- Erre azért van szükség, hogy a böngésző meg tudja jeleníteni az ékezetes magyar betüket -->
<meta charset="utf-8">
<!-- Hivatkozunk a hello_vilag2.js kódfájlra -->
<script src="hello_vilag2.js" type="text/javascript"></script>
</head>
@gergob
gergob / hello_vilag2.js
Created October 23, 2013 18:14
FLOSSzine - Programozás Kezdőkenk - Bevezető - Hello Világ!
console.log("Hello Világ");
@gergob
gergob / hello.html
Created October 23, 2013 16:28
FLOSSzine - Programozás Kezdőkenk - Bevezető - Hello Világ!
<!-- HTML fájlokba ezen jelek közzé lehet kommentárokat tenni -->
<!DOCTYPE html>
<html>
<!-- HTML dokumentum fej része -->
<head>
<!-- Erre azért van szükség, hogy a böngésző meg tudja jeleníteni az ékezetes magyar betüket -->
<meta charset="utf-8">
<!-- Hivatkozunk az előzőekben megírt JavaScript kódfájlunkra -->
<script src="hello_vilag.js" type="text/javascript"></script>
@gergob
gergob / hello_vilag.js
Created October 23, 2013 16:17
FLOSSzine - Programozás Kezdőkenk - Bevezető - Hello Világ!
//minden szöveg, amelyet // előz meg,
//illetve /* ... */ jelek közzé teszünk
//a JavaScript kommentként kezeli és figyelmen kívül hagyja
alert("Hello Világ!");
@gergob
gergob / fstat.js
Created July 26, 2013 21:17
contains the node.js fstat methods
//
// Method names taken from: http://nodejs.org/api/fs.html#fs_class_fs_stats
//
//stats is the return value if fs.statsync(PATH_TO_FILE) method
stats.isFile();
stats.isDirectory();
stats.isBlockDevice();
stats.isCharacterDevice();
stats.isSymbolicLink(); //(only valid with fs.lstat())
@gergob
gergob / wc.js
Created July 26, 2013 21:03
Contains the implementation of the wc linux command using node.js
#!/usr/bin/env node
/*
This small node.js app should do exactly what the wc linux command does.
Quote from man wc:
Print newline, word, and byte counts for each FILE, and a total line if more than one FILE is specified. With no FILE, or when FILE is -, read standard
input. A word is a non-zero-length sequence of characters delimited by white space. The options below may be used to select which counts are printed,
always in the following order: newline, word, character, byte, maximum line length.