Skip to content

Instantly share code, notes, and snippets.

Gergo Bogdan gergob

Block or report user

Report or block gergob

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@gergob
gergob / buildAnimal.js
Created Nov 24, 2012
buildAnimal function
View buildAnimal.js
buildAnimal: function (model) {
var newAnimal = new Zoo.Animal();
if (model.hasOwnProperty("name")) {
newAnimal.setName(model.name);
}
if (model.hasOwnProperty("age")) {
newAnimal.setAge(model.age);
@gergob
gergob / loadZoo.js
Created Nov 24, 2012
loadZoo function
View loadZoo.js
loadZoo: function (uri) {
//IMPORTANT TO RETURN THE PROMISE
return Windows.Storage.StorageFile.getFileFromApplicationUriAsync(uri)
.then(function (file) {
return Windows.Storage.FileIO.readTextAsync(file)
.then(function (textFromFile) {
var myParsedJsonData = JSON.parse(textFromFile);
//this will store all the new animals transferred to zoo
var zoo = new Array();
@gergob
gergob / processAndDisplayZooJSON.js
Created Nov 24, 2012
Process and display zoo.json
View processAndDisplayZooJSON.js
args.setPromise(WinJS.UI.processAll().then(function() {
//build up the URL for the file added to the project
var url = new Windows.Foundation.Uri("ms-appx:///zoo.json");
//this will store the imported data
var myNewAnimals = new Array();
//invoke the static method which loads the file
//and creates Animal objects from json data
@gergob
gergob / zoo.json
Created Nov 24, 2012
Data of transferred animals
View zoo.json
[{
"name" : "King",
"age" : 5,
"hoursSinceLastFeed" : 3
},
{
"name" : "Geeko",
"age" : 2,
"hoursSinceLastFeed" : 12
},
View Animals.js
/// <reference path="//Microsoft.WinJS.1.0/js/base.js" />
/// <reference path="//Microsoft.WinJS.1.0/js/ui.js" />
(function () {
"use strict";
WinJS.Namespace.define("Zoo", {
Animal: WinJS.Class.define(
@gergob
gergob / terminal.py
Last active Aug 29, 2015
Colorful console in Python
View terminal.py
from blessings import Terminal
if __name__ == "__main__":
# create a new instance of Terminal class
terminal = Terminal()
print("Your terminal supports {0} different colors.\n".format(terminal.number_of_colors))
indentation = 3 * terminal.move_right()
View user_login_needed.py
# decorator for Flask application methods
def user_login_needed(f):
@wraps(f)
def decorated_function(*args, **kwargs):
is_user_logged_in = session['user_logged_in']
if not is_user_logged_in:
return redirect(url_for('login'))
else:
return f(*args, **kwargs)
return decorated_function
View login.py
@app.route("/")
@user_login_needed
def index():
return render_template("index.html")
return user_login_needed(index) # no extra parameters passed since index does not take any parameters
@app.route("/login", methods=["GET", "POST"])
def login():
View simple_flask_app.py
from flask import Flask
# initialize a new Flask app
app = Flask(__name__)
# add one routing
@app.route("/")
def index():
return "Homepage routing works!"
View contacts_template.html
{% extends "index.html" %}
{% block title %}Contacts{% endblock %}
{% block content %}
<h2>Contacts</h2>
{% if contacts %}
<p>There are {{ contacts | length }} contacts in the database.</p>
{% if contacts|length > 0 %}
You can’t perform that action at this time.