text:
Functional Reactive Programming on Android With RxJava
------------------------------------------------------

Shameless plug: if after reading this article, you want to know more,
come hear me talk at [DroidCon UK 2013](http://uk.droidcon.com/2013/lineup/)!

If you are an application developer, there are two inconvenient truths:

1.  Modern applications are inherently concurrent.
2.  Writing concurrent programs that are correct is difficult.

In the domain of mobile or desktop applications, parallel execution
allows for responsive user interfaces because we can move computations
into the background while the UI responds to ongoing user interactions.
Code must execute concurrently to not stray from this fundamental
requirement. Writing such programs is diffcult because on mobile they
are typically written in imperative languages like C or Java. Writing
concurrent code in imperative languages is difficult because code is
written in terms of interweaved, temporal instructions that move objects
or data structures from one state to another. This imperative style of
programming inherently produces side effects. It presents several
problems when running instructions in parallel, such as race conditions
when writing to a shared resource.

Resistance is futile–or is it?
==============================

Developers have grown accustomed to the drawbacks of expressing
concurrency in imperative languages. On platforms like Android where
Java is (still) the dominant language, concurrency simply sucks, and we
should just give in and deal with it. I personally keep a close eye on
the server side end of the spectrum. Over the past few years, functional
programming has made an astounding comeback in terms of rate of adoption
and innovation, the details of which I will not get into here. In the
case of concurrency, functional programming has a very simple answer to
dealing with shared state: don’t have it.

Problems of concurrent programming with AsyncTask
-------------------------------------------------

Being based on Java, Android comes with a standard number of Java
concurrency primitives such as `Thread`s and `Future`s. While these
tools make it easy to perform simple asynchronous tasks, they are fairly
low level and require a substantial amount of diligence when you use
them to model complex interactions between concurrent objects. A
frequent use case on Android or any UI-driven application is to perform
a background job and then update the UI with the result of the
operation. Android provides `AsyncTask` for exactly that:

    class DownloadTask extends AsyncTask<String, Void, File> {

      protected File doInBackground(String... args) {
        final String url = args[0];
        try {
          byte[] fileContent = downloadFile(url);
          File file = writeToFile(fileContent);
          return file;
        } catch (Exception e) {
          // ???
        }
      }

      protected void onPostExecute(File file) {
        Context context = getContext(); // ???
        Toast.makeText(context,
            "Downloaded: " + file.getAbsolutePath(),
            Toast.LENGTH_SHORT)
            .show();
      }
    }

This looks straightforward. Define a method `doInBackground` that
accepts something through its formal parameters, and returns something
as the result of the operation. Android guarantees that this code will
execute in a thread that is not the main user-interface thread. We also
define a UI callback function `onPostExecute` that receives the result
of the computation and can consume it on the main UI thread, since
Android guarantees that this method will always be invoked on the main
thread.

### In search for the jigsaw-puzzle pieces

So far so good. What’s wrong with this picture? Let’s start with
`doInBackground`, which downloads a file–a costly operation because it
involves network and disk I/O. There are many things that can go wrong,
so we want to recover from errors, and add a try-catch block. What do we
do in the catch block? Log the error? Perhaps we want to inform the user
about this error too, which likely involves interacting with the UI.
Wait, we cannot do that because we are not allowed to update any
user-interface elements from a background thread. Bummer.

It should be easy to handle that error in `onPostExecute`. We might
reason that it is as simple as holding on to the exception in a private
field (i.e. we write it on the background thread), and check in
`onPostExecute` (i.e. read it on the UI thread) if that field is set to
something other than null (did I mention we love null checks) and
display it to the user in some way shape or form. But wait, how do we
obtain a reference to a `Context`, without which we cannot do anything
meaningful with the UI? Apparently, we have to bind it to the task
instance up front, at the point of instantiation, and keep a reference
to it throughout a task’s execution. But what if the download takes a
minute to run? Do we want to hold on to an `Activity` instance for an
entire minute? What if the user decides to back out of the Activity that
triggered the task, and we are holding on to a stale reference. This not
only creates a substantial memory leak, but is also worthless because
meanwhile it has been detached from the application window. A problem
that [everyone is well aware of](https://www.google.de/search?q=asynctask+configuration+change).

### Beyond the basics

There are other problems with all this. The preceding task is incredibly
simple. Picture a more complicated scenario where we need to orchestrate
a number of such operations. For example, we might want to fetch some
JSON from a service API, parse it, map it, filter it, cache it to disk,
and only then feed the result to the UI. All the aforementioned
operations should–as per the single responsibility principle–exist as
separate objects, perhaps exposed through different services. It is
difficult and non-intuitive to use `AsyncTask` because it requires
grouping any number of combinations of service interactions into
separate task classes. This results in a proliferation of meaningless
task classes, from the perspective of your business logic.

Another option is to have one task class per service-object invocation,
or wrap the service objects themselves in `AsyncTasks`. Composing
service objects means nesting `AsyncTask`, which leads to what is
commonly referred to as “callback hell” because you start tasks from a
task callback from a task callback from a … you get the idea.

Last but not least, `AsyncTask`s scheduling behavior varies
significantly across different versions of Android. It’s changed from a
capped thread pool in the 1.x days (with varying bounds depending on the
API level) to a *single thread executor* model in 4.x. Read that again.
Your tasks (plural) do *not* run concurrently to each other on ICS
devices and beyond (although they do run concurrently to the main UI
thread). Why did Google decide to serialize task execution? Developers
could not get it right, applications suffered from nasty problems due to
race conditions and incorrectly synchronized code.

### The inconvenient truth

Should we still use `Thread` and `AsyncTask`?

The answer is “probably”. For simple, one-shot jobs that do not require
much orchestration, `AsyncTask` is fine. For anything more complex it is
doable, but requires juggling with `volatile`s, `WeakReference`s, `null`
checks, and other [defensive, unconfident mechanisms](http://devblog.avdi.org/2012/06/05/confident-ruby-beta/).
Perhaps worst of all, it requires you to think about things that have
nothing to do with the problem that you set out to solve, which is
 to download a file.

Enter RxJava–now with more Android
==================================

To come back to the initial problem statement, do we have to give in to
the lack of high-level abstractions and deal with it, or do better
solutions exist? Turns out that functional programming might have an
answer to this. “But wait” you might say, “I still wanna use Java?”.
Turns out, yes, you can. It is not super pretty (at least not unless
Google whips out its magic wand and gives us Java 8 and closures on
Dalvik, or unless you feel attracted to anonymous classes and six levels
of identation). However, it solves all of the problems in one fell
swoop:

-   No standard mechanism to recover from errors
-   Lack of control over thread scheduling (unless you like to dig deep)
-   No obvious way to compose asynchronous operations
-   No obvious and hassle-free way of attaching to `Context`

[RxJava](https://github.com/Netflix/RxJava) is an implementation of the
Reactive Extensions (Rx) on the JVM, courtesy of Netflix. Rx was first
conceived by Erik Meijer on the Microsoft .NET platform, as a way of
combining data or event streams with reactive objects and functional
composition. In Rx, events are modeled as observable streams to which
observers are subscribed. These streams, or observables for short, can
be filtered, transformed, and composed in various ways before their
results are emitted to an observer. Every observer is defined within
three messages: `onNext`, `onCompleted`, and `onError`. Concurrency is a
variable in this equation, and abstracted away in the form of
schedulers. Generally, every observable stream exposes an interface that
is modeled after concurrent execution flows (i.e. you don’t call it, you
subscribe to it), but by default is executed synchronously. Introducing
schedulers can make an observable execute using various concurrency
primitives such as threads, thread pools, or even Scala actors. Here is
an example:

    Subscription sub = Observable.from(1, 2, 3, 4, 5)
        .subscribeOn(Schedulers.newThread())
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe(observer);

    // ...

    sub.unsubscribe();

This creates a new, observable stream from the given list of integers,
and emits them one after another on the given observer. The use of
`subscribeOn` and `observeOn` configures the stream to emit the numbers
on a new `Thread`, and to receive them on the Android main UI thread.
For example, the observer’s `onNext` method is called on the main
thread. Eventually, you unsubscribe from the observable. Here is an
example `Observer` implementation:

    public class IntObserver implements Observer<Integer> {

      @Override
      public void onNext(Integer value) {
         System.out.println("received: " + value);
      }

      // onCompleted and onError omitted
      ...
    }

For something more interesting, you can implement the download task as
an Rx `Observable`:

    private Observable<File> downloadFileObservable() {
        return Observable.create(new OnSubscribeFunc<File>() {
            @Override
            public Subscription onSubscribe(Observer<? super File> fileObserver) {
                try {
                    byte[] fileContent = downloadFile();
                    File file = writeToFile(fileContent);
                    fileObserver.onNext(file);
                    fileObserver.onCompleted();
                } catch (Exception e) {
                    fileObserver.onError(e);
                }
                return Subscriptions.empty();
            }
        });
    }

The preceding example creates a method that builds an `Observable`
*stream*, which in this case only ever emits a single item (the file) to
which a `File` observer can connect. Whenever this observable is
subscribed to, its `onSubscribe` function triggers and executes the task
at hand. If the task can be carried out successfully, deliver the result
to the observer through `onNext` so `onNext` can properly react to it.
Then signal completion by using `onCompleted`. If an exception is
raised, deliver it to the observer through `onError`. As an example, you
can use this from a `Fragment`:

    class MyFragment extends Fragment implements Observer<File> {
      private Subscription subscription;

      @Override
      protected void onCreate(Bundle savedInstanceState) {
        subscription = AndroidObservables.fromFragment(this, downloadFileObservable())
                              .subscribeOn(Schedulers.newThread())
                              .subscribe(this);
      }

      private Observable<File> downloadFileObservable() { /* as above */ }

      @Override
      protected void onDestroy() {
        subscription.unsubscribe();
      }

      public void onNext(File file) {
        Toast.makeText(getActivity(),
            "Downloaded: " + file.getAbsolutePath(),
            Toast.LENGTH_SHORT)
            .show();
      }

      public void onCompleted() {}

      public void onError(Throwable error) {
        Toast.makeText(getActivity(),
            "Download failed: " + error.getMessage(),
            Toast.LENGTH_SHORT)
            .show();
      }
    }

By using RxJava, the aforementioned issues are solved all at the same
time. The `fromFragment` call transforms the given source observable in
such a way that events will only be emitted to the fragment if it’s
still alive and attached to its host activity. Call `unsubscribe` in
`onDestroy` to ensure that all references to the fragment, which is also
the observer, are released.

You can have proper error handling through an observer’s `onError`
callback. Also, you can execute the task on any given scheduler with a
simple method call.  Futhermore,
RxJava allows you to compose and transform observables to obtain new
ones, which enables you to reuse code easily. For example, to not emit
the `File` itself, but merely its path, transform the *existing*
observable:

    Observable<String> filePathObservable = downloadFileObservable().map(new Func1<File, String>() {
        @Override
        public String call(File file) {
            return file.getAbsolutePath();
        }
    });

    // now emits file paths, not `File`s
    subscription = filePathObservable.subscribe(/* Observer<String> */);

You can see how powerful this way of expressing asynchronous
computations is. At [SoundCloud](https://soundcloud.com), we are moving
most of our code that relies heavily on event-based and asynchronous
operations to Rx observables. For convenience, we contributed
`AndroidSchedulers` that schedule an observer to receive callbacks on a
`Handler` thread. See [rxjava-android](https://github.com/Netflix/RxJava/tree/master/rxjava-contrib/rxjava-android).
We are also in the process of contributing those operators back that
allow observing observables from Fragments and Activities in an easy and
safe way, as seen in the previous example.

In a nutshell, RxJava finally makes concurrency and event-based
programming on Android hassle free. Note that we follow the same
strategy on iOS using GitHub’s [Reactive Cocoa](https://github.com/ReactiveCocoa/ReactiveCocoa) library because
we have committed ourselves to the functional-reactive paradigm. We
think that it is an exciting development that leads to code that is more
stable, easier to unit test, and free of low-level state or concurrency
concerns that would otherwise take over your service objects.

To hear more about this topic, watch this [interview with our Director
of Mobile Engineering on Root Access Berlin](http://backstage.soundcloud.com/2013/08/responsive-android-applications-with-sane-code/) and come see me at [DroidCon UK 2013](http://uk.droidcon.com/2013/lineup/) where I will be speaking about RxJava and its use in the SoundCloud application on the developer
track.

Aug 25th, 2013

Copyright © 2014 Matthias Käppler

repository: morristech/android-prep

repo_name: morristech/android-prep


text:
Html5
=====

Trying to learn html canvas drawing

## Synopsis

At the top of the file there should be a short introduction and/ or overview that explains **what** the project is. This description should match descriptions added for package managers (Gemspec, package.json, etc.)

## Code Example

Pending

## Motivation

I need to learn how to make HTML5 Canvas apps, jQuery, Angular and generally learn how to make web-apps

## Installation

NA

## API Reference

Depending on the size of the project, if it is small and simple enough the reference docs can be added to the README. For medium size to larger projects it is important to at least provide a link to where the API reference docs live.

## Tests

Describe and show how to run the tests with code examples.
Really need to get a test framework shoehorned in here.
## License

Apache Licence

branch_name: refs/heads/master

extension: md

license_type: permissive


text:
CompSoc's 2015 Website Revamp - http://ulcompsoc.org.uk
=======================================================

Required feature checklist:
- [x] User Management System
    - [x] Admin/regular user distinction
    - [x] Batch user creation system
    - [x] Audit system for admin actions
- [x] Portfolio
    - [x] Viewing page
    - [x] Pull from UoLCompSoc Github feed
- [x] Points Tracking System
    - [x] Admin console
    - [x] Leaderboard
    - [x] Audit system
- [x] Informational pages
    - [x] About Us
    - [x] Social Media links
- [ ] Some sort of game!
- [ ] Security audit (XSS) + improvements
- [ ] Questions section

There is scope to do more, but the above are the core requirements.

Contact
=======

Project Lead - [Ashley Davis : SgtCoDFish](https://github.com/SgtCoDFish)
Backup Lead + Technical Assistant - [Alex Spiers](https://github.com/alexspiers)

license: MIT


text:
```
                        __                             __ __
.----.-----.---.-.-----|  |_.-----.----.--------.-----|  |  |_
|  __|  _  |  _  |__ --|   _|  -__|   _|        |  -__|  |   _|
|____|_____|___._|_____|____|_____|__| |__|__|__|_____|__|____|
--A fun way to break your Blu-Ray burner-----------------------
```

The **coastermelt** project is an effort to make open source firmware for creatively repurposing BD-R drives.

Follow the video channel:  https://vimeo.com/channels/coastermelt

The new firmware is still not real yet, this project is still in the early stages of reverse engineering.

What it has
-----------

For the Samsung SE-506CB external Blu-Ray burner, it provides a way to install 'backdoored' firmware to support a set of programmatic and interactive reverse engineering tools.

Mac OS X only for now. Requires an ARM cross compiler (arm-none-eabi-gcc and friends) as well as a local compiler (XCode).

NOTE that there are NO copyrighted firmware images included here in this open source project! To be on the safe side, we don't include large disassemblies or reverse engineering databases either. The installation process requires patching a specific version of firmware, which we download from the official firmware update site during the build process.

The documentation here is an original effort created without access to any data sheets or official documentation for the MT1939 chip. I started with a marketing blurb about the chip, the "ARM" logo lasered on top, and some firmware updates. Everything else here is based on extensive guesswork and experimentation. If anything sounds authoritative, that is completely by accident. I have no idea what I'm doing here.

Parts
-----

* doc - Reverse engineering notes, sketchy DIY hardware doumentation
* flasher - Command line tool to flash firmware
    - The official tool is annoying and the Mac version is broken. So this.
    - Also it has some weird debug features, naturally
    - And there's a Python tool to patch the firmware checksum and bypass its cryptographic signatures.
* backdoor - Debugging tools based on binary patching official firmware
    - The assembly code in patch.s gets planted in a SCSI callback
    - A bunch of weird Python stuff uses that as a debug stub

Getting Started
---------------

* Get XCode, right?
* Also this compiler. Put it in your path or something: [arm-none-eabi-gcc](https://launchpad.net/gcc-arm-embedded/+download)
* Yet another weird compiler. With [homebrew](http://brew.sh), do `brew install sdcc`
* You probably want to have [IPython](http://ipython.org/install.html) too. It's great, and the cool debug shell needs it.
* You usually want to have **no disc** in the drive or have the tray ejected when you start working with it. Otherwise, the OS can keep us from claiming the device.
* Run **make** in the `backdoor` directory to build the patched firmware and the Python extensions
* If you're paranoid like me, **make disassemble** will show you the damage
* If you're ready to toast your drive, run **make flash**

If the update worked, you'll see my backdoor signature show up when you run mtflash. This is how you can tell your drive has the patch! Otherwise it should mostly work, though of course it's totally untrustworthy at this point.
Firmware version:
       0: 00 06 01 01 54 53 20 00                          ....TS .
Backdoor signature:
       0: 7e 4d 65 53 60 31 34 20 76 2e 30 33              ~MeS`14 v.03
```

But hooray! Now if you have IPython, you can start the interactive shell. For more about what you can do with it, take a look at the [shell recipe book](https://github.com/scanlime/coastermelt/blob/master/doc/cmshell-recipes.txt).

```
cylindroid:backdoor micah$ ./cmshell.py

                        __                             __ __
.----.-----.---.-.-----|  |_.-----.----.--------.-----|  |  |_
|  __|  _  |  _  |__ --|   _|  -__|   _|        |  -__|  |   _|
|____|_____|___._|_____|____|_____|__| |__|__|__|_____|__|____|
--IPython Shell for Interactive Exploration--------------------

Read, write, or fill ARM memory. Numbers are hex. Trailing _ is
short for 0000, leading _ adds 'pad' scratchpad RAM offset.
Internal _ are ignored so you can use them as separators.

    rd 1ff_ 100
    wr _ 1febb
    ALSO: rdw, orr, bic, fill, watch, find
          peek, poke, read_block

Disassemble, assemble, and invoke ARM assembly:

    dis 3100
    asm _4 mov r3, #0x14
    dis _4 10
    ea mrs r0, cpsr; ldr r1, =0xaa000000; orr r0, r1
    ALSO: tea, blx, assemble, disassemble, evalasm

Or compile and invoke C++ code with console output:

    ec 0x42
    ec ((uint16_t*)pad)[40]++
    ecc println("Hello World!")
    ALSO: console, compile, evalc

Live code patching and tracing:

    hook -Rrcm "Eject button" 18eb4
    ALSO: ovl, wrf, asmf

You can use integer globals in C++ and ASM snippets,
or define/replace a named C++ function:

    fc uint32_t* words = (uint32_t*) buffer
    buffer = pad + 0x100
    ec words[0] += 0x50
    asm _ ldr r0, =buffer; bx lr

You can script the device's SCSI interface too:

    sc c ac              # Backdoor signature
    sc 8 ff 00 ff        # Undocumented firmware version
    ALSO: reset, eject, sc_sense, sc_read, scsi_in, scsi_out

Happy hacking!    -- Type 'thing?' for help on 'thing' or
~MeS`14              '?' for IPython, '%h' for this again.

In [1]:
```

gha_license_id: MIT


text:
Overview
========

PsRealVehicle is the plugin for [Unreal Engine 4](https://www.unrealengine.com/) with simple force-driven vehicle simulation.

Key features:
 * **@TODO** Plugin in development mode!!!

Check the [Wiki](https://github.com/PushkinStudio/PsRealVehicle/wiki) tab for plugin usage examples and installation notes.

Current version: **1.0 Alpha 1** (UE 4.10)

![SCREENSHOT](SCREENSHOT.jpg)

Legal info
----------

Unreal® is a trademark or registered trademark of Epic Games, Inc. in the United States of America and elsewhere.

Unreal® Engine, Copyright 1998 – 2016, Epic Games, Inc. All rights reserved.

repository: dantonov/PsRealVehicle

branch_name: refs/heads/develop

repo_name: dantonov/PsRealVehicle


text:
---
layout: default
title:  "Full Tutorial"
date:   2017-03-03 09:15:22 -0500
category: SQLAlchemy
tags: sqlalchemy tutorial
published: true
---
# SQLAlchemy

Do you want to efficiently and easily interact with an SQL database in Python, but you're tired of creating those **pesky** SQL statements? Look no further.  SQLAlchemy is one of the best Python libraries for performing CRUD (create, read, update, and delete) operations on your databases. Tables are simply custom classes and rows are simply objects of those classes. It's very clean and easy to read, and the best part about it is you ***never*** have to write another SQL statement ever again!

### Table of contents
{:.no_toc}

* Table of contents placeholder
{:toc}

## I) Installation
It's highly recommended to install all of your packages into a **`virtualenv`** that you're going to be using for this project. It helps keep your packages nice and orderly. If you're **not** using **`virtualenv`**, skip the next two steps.

```
virtualenv sqlalchemy-tut
sqlalchemy-tut\Scripts\activate
```

Your command prompt should now have your **`virtualenv`** as a prefix to your path.

```
(sqlalchemy-tut) C:\Users\Admin\Development\Tutorials>
```

Once you have your **`virtualenv`** activated, you can now install **`sqlalchemy`**.

```
pip install sqlalchemy
```

For this tutorial, **`sqlalchemy-1.1.5`** will be used. We're going to have two files, **`main.py`** for all of the database-related code, and **`models.py`** for our tables that we're going to create.

## II) Getting Connected in **main.py**

### Imports
First, we need to set up the imports that we're going to need to set up the database connector.

```python
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from models import Base, Account
```

**Note:** We have not created `models` yet so this will not successfully run yet.

### Database URI
Once we have the proper packages imported, we need to connect to the database that we're going to use. The format of the URI goes like this:

**`dialect`** is the type of database such as **`sqlite`**, **`mysql`**, **`postgresql`**, etc. For a list of supported dialects, check out [the documents.](http://docs.sqlalchemy.org/en/latest/core/engines.html)
**`driver`** is optional - if not specified, it will default to the most widely used driver for that **`dialect`**.

```python
database_uri = "dialect+driver://username:password@host:port/database"
```

For this tutorial, we will be using **`sqlite`**. Notice the extra **`/`** for **`sqlite`** - this is needed because there is no host.

```python
database_uri = "sqlite:///sqlalchemy-tutorial.db"
```

### Engine

Next, we need to set up the **`engine`**. The **`engine`** is what SQLAlchemy uses to give us the connection to our **`database_uri`**.

```python
engine = create_engine(database_uri, echo=True)
```

If **`echo`** is True, SQLAlchemy will display any SQL queries via the standard logging (in our case, the console).
If **`echo`** is **`"debug"`**, then any queries returning rows will be printing via logging as well.

### Session

```python
Session = sessionmaker(bind=engine)
session = Session()
```

The **`session`** is everything that pertains to the database at the current time. It will be used later for all of our operations such as: inserting, updating, deleting, selecting and committing. The **`bind`** paramater points SQLAlchemy to what engine we're using.

### Creating the Tables in the Database

```python
Base.metadata.create_all(engine)
```

**`Base`** is imported from **`models.py`**; it's the "backbone" of all of our table classes. Once we call **`create_all()`**, the SQLAlchemy will create all of our tables that we have associated with Base. Currently, we do not have any tables.

## III) Table Classes in **models.py**

For the sake of keeping everything nice and organized, we're going to be putting all of our models in **`models.py`**. Our database connectivity and other database actions will be kept in **`main.py`**.

### Imports

```python
from sqlalchemy import Column, Integer, String, Boolean, DateTime
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.sql import func
```

The first import from **`sqlalchemy`** will give us the ability to make our columns in our table. You need not import all of the ones listed.

The second import allows us to use **`declarative_base`**. As mentioned previously, this is the "backbone" of all of our table classes.

The third import, while optional, will allow us to set a default time value in one of our columns.

### Base

```python
Base = declarative_base()
```

All of our custom table classes will extend off of **`Base`**. Think of **`Base`** just as the "base model" for a class. It has all of the inner workings, we're just putting custom touches on it.

### Creating a Table

A new table in our database is simply a sub-class of **`Base`**. For this tutorial, we're going to be creating a simple **`Account`** table. Accounts will have a unique identifier, a username and password, 10 tokens, a verified status, and the date in which the account was created.

First, all you have to do is extend the **`Base`** class.

```python
class Account(Base):
    __tablename__ = 'accounts'
```

The value of **`__tablename__`** defaults to the lowercase of our class name. We override it here since the table will have multiple accounts, so it makes sense to call the name of the table **`accounts`**.

### Adding Columns

Once we have our basic **`Account`** class set up, we can start adding in our columns. The format for a column is as follows:

```python
column_name = Column(column_type, **kwargs)
```

There are several different optional parameters (kwargs) that you can pass in to **`Column()`**, such as **`default`**, **`primary_key`**, and **`unique`**. To see the full list of possible parameters, check out [the documentation for Column](http://docs.sqlalchemy.org/en/latest/core/metadata.html#sqlalchemy.schema.Column.__init__ "Column").

**`column_type`** is the type of column, such as **`String`**, **`Integer`**, **`Boolean`**, and **`DateTime`**. For **`String`**, you can pass in a maxlen by calling **`String(maxlen)`**. To see the full list of the different types, check out [the documentation for Types](http://docs.sqlalchemy.org/en/latest/core/type_basics.html "Type Basics").

```python
class Account(Base):
    __tablename__ = 'accounts'

    id = Column(Integer, primary_key=True)
    username = Column(String, unique=True)
    password = Column(String(64))
    tokens   = Column(Integer, default=10)
    verified = Column(Boolean, default=False)
    date_created = Column(DateTime, server_default=func.now())
```

Here, we use **`id`** as our **`primary_key`** (a unique identifier that auto-increments for each row).

**`username`** is a unique **`String`**. No two accounts can have the same username. If we try to add in two of the same usernames, SQLAlchemy will raise an [**`sqlalchemy.exc.IntegrityError`**](http://docs.sqlalchemy.org/en/latest/core/exceptions.html "SQLAlchemy Exceptions").

**`password`** is a **`String`** with a maximum length of 64 characters. **Note:** the enforcement of the maximum length when inserting a row depends on the dialect used. If you want a strict enforcement, you will need to check the length of the value **before** inserting it.

**`tokens`** is an **`Integer`** with a default value of **10**. We want all of our accounts to start with 10 tokens.

**`verified`** is a **`Boolean`** with a default value of **`False`**. When accounts are created, they have yet to be verified. Inside of databases, **`Booleans`** are represented as 0 (**False**) and 1 (**True**).

**`date_created`** is a **`DateTime`** object that defaults to **`CURRENT_TIMESTAMP`**. We use **`server_default`** when working with **`DateTime`** so that the value is set when the database recieves the information. **`func.now()`** returns the appropriate **`CURRENT_TIMESTAMP`** for the chosen dialect.

### Overriding **__repr__()** in **Account**
Later on, when we query our database and get results back, they will look something like this:

```python
<models.Account object at 0x0390BBF0>
```

What account is that? What's the username? How many tokens does it have? If we want to answer those questions, we need to override **`__repr__`** in our **`Account`** class. Check out [String Formatting with a Class](http://pythonforalayman.com/string-formatting-with-a-class#usage-positional-arguments) for more information on this.

```python
def __repr__(self):
    return "<Account U: {0.username} T: {0.tokens} V: {0.verified}>".format(self)
```

Now, our results will like this:

```python
<Account U: admin T: 20 V: False>
```

Much better!

## IV) Database CRUD Interaction in **main.py**

Once we have our `Account` table set up and created in the database, we can now start interacting with it.

### Creating New Rows

#### Via Constructor

```python
guest = Account(username="guest", password="anonymous")
admin = Account(username="admin", password="admin_password", tokens=20)
```

To create a new **`Account`** to be added to the database, all you have to do is simply create a new **`Account`** object. Each column is passed in as a kwarg. If you do not specifically pass in a column, it will default to the **`default`** value that was set when you created the column earlier (or **`None`** if you didn't set that).

In this example, **`guest`** will start off with **10** tokens since that was the default that we defined. The **`admin`** account will start of with **20** tokens since we specifically passed it in.

#### Via Properties
```python
guest = Account(username="guest")
guest.password = "anonymous"

admin = Account(tokens=20, verified=True)
admin.username = "admin"
admin.password = "admin_password"
```

As you can see, you can mix and match setting different values through the class constructor and through properties of the object itself. This is useful if you need to perform logic on different values before you commit the account to the database.

**Note**: These new accounts do not exist in our database yet - they're only in memory!

***

### Saving to the Database

All interaction with our database will be through our **`session`** variable that we created earlier. Whenever we create, modify, or delete objects, that changes are only stored temporarily in memory. To save it to the database, we have to **`add`** our object to our **`session`** and then **`commit`** the changes.

```python
guest = Account(username="guest", password="anonymous")
admin = Account(username="admin", password="admin_password", tokens=20)

session.add(guest)
session.add(admin)
session.commit()
```

**Note:** **`session.add()`** can take a list of objects such as **`session.add([guest, admin])`**

Now, if we were to check our **`sqlalchemy-tutorial.db`** file, we would notice two rows. Let's fetch them now!

***

### Selecting Rows from the Database

As mentioned earlier, all of our interaction with our database is with our **`session`** variable. To query the database, we use the **`.query(Table)`** function.

#### Select All Rows

```python
all_users = session.query(Account).all()
```

If we just want to get all of the rows in our **`Accounts`** table matching our query, we simply use **`.all()`**.

#### Select The First Row

```python
first_user = session.query(Account).first()
```

If we just want the first user matching our query, we simply use **`.first()`**. In all instances where you see **`.all()`**, you can replace it with **`.first()`** if that suits what you need.

#### Selecting Specific Rows

To select rows with specific values, we can use **`.filter()`** and **`.filter_by()`**.

For **`.filter()`**, the parameters are SQL expressions.

```python
users = session.query(Account).filter(Account.tokens == 10).all()
>>> [<Account U: guest T: 10 V: False>]
```

Since only one account has 10 tokens, this query will only return the **`guest`** account.

We can chain together different expressions if we want.

```python
users = session.query(Account).filter(Account.tokens == 10, Account.verified == True).all()
>>> []
```

For **`.filter_by()`**, the parameters are simply keyword arguments. As previously, these arguments are chainable as well.

```python
users = session.query(Account).filter_by(tokens=10).all()
>>> [<Account U: guest T: 10 V: False>]
```

### Updating a Row

To update a row, first we need to fetch the object that we want. Afterwards, we can set whatever values we want. Let's change the password.

```python
admin = session.query(Account).filter_by(username="admin").first()
admin.password = "new_password"
```

In the database, admin's password is still **admin_password**. As mentioned earlier, we need to **add** our object to our session and then **commit** it to the database.

```python
admin = session.query(Account).filter_by(username="admin").first()
admin.password = "new_password"
session.add(admin)
session.commit()
```

Now, if we were to check our database file, admin's password is now saved as **new_password**!

### Deleting a Row

To delete a row, fetch the object that you want and then **`.delete()`** it from the session. Don't forget to commit!

```python
guest = session.query(Account).filter_by(username="guest").first()
session.delete(guest)
session.commit()
```

extension: markdown


text:
# Setup guide for Raspbian

I went with manual installation, so installation wih NOOBS is not tested.

## Table of Contents
* [Install with NOOBS](#install-with-noobs)
    * [Download SD card formatter](#download-sd-card-formatter)
    * [Format card](#format-card)
    * [Download NOOBS](#download-and-extract-noobs)
* [Manual installation](#manual-installation)
    * [Download image](#download-image)
    * [Download balenaEtcher](#download-balenaetcher)
    * [Flash SD card](#flash-sd-card)
    * [Allow ssh connections](#allow-ssh-connections)
* [Connect to Raspberry](#connect-to-raspberry)
    * [Generate and add shh keys](#generate-and-add-ssh-keys-for-easier-access)

## Install with NOOBS

### Download SD card formatter
Download link: https://www.sdcard.org/downloads/formatter/

### Format card
Simply open previously downloaded formatter, find your card and click `Quick format`

### Download and extract NOOBS
Should be pretty straight forward.

## Manual installation
Some video tutorial containing most of the information: https://www.youtube.com/watch?v=Zi1dIXxu_Qw

### Download image
List of images can be found here: https://www.raspberrypi.org/downloads/
We are going with Raspbian Buster Lite as this is specially designed for Raspberry and we
do not need desktop features.
Simply download zip file, no need to extract it.

### Download balenaEtcher
Download link: https://www.balena.io/etcher/
I didn't need to do any installation, worked out of the box.

### Flash SD Card
1. Open balenaEtcher
2. Select image you previously downloaded (zip containing it)
3. Select SD card (if not already selected)
4. Click `Flash`
**Note that this will erase everything from card!**
For me the formatting failed on first try, I simply ran again with same settings and everything worked now.

### Allow ssh connections
Open boot partition of SD card. (You might need to reconnect SD card reader)
Create empty file named `ssh` to allow ssh connections.
```bash
# In boot partition
touch ssh
```

## Connect to Raspberry
Connect on local network
```bash
ssh pi@raspberrypi
# Default password is raspberry
```

### Generate and add ssh-keys for easier access
Generate keys on your computer
```bash
ssh-keygen
```
After entering the command, you should see the following output:
```bash
Output
Generating public/private rsa key pair.
Enter file in which to save the key (/your_home/.ssh/id_rsa):
```
Enter `id_pi-runner` to save the key pair into the .ssh/ subdirectory in your home directory with name `id_pi-runner`
After that you should then see the following prompt:
```bash
Output
Enter passphrase (empty for no passphrase):
```
Here you optionally may enter a secure passphrase, which we will skip.
Simply press `ENTER` (with empty input)
You should then see the following output:
```bash
Output
Your identification has been saved in /your_home/.ssh/id_webstore.
Your public key has been saved in /your_home/.ssh/id_webstore.pub.
The key fingerprint is:
a9:49:2e:2a:5e:33:3e:a9:de:4e:77:11:58:b6:90:26 username@remote_host
The key´s randomart image is:
+--[ RSA 2048]----+
|     ..o         |
|   E o= .        |
|    o. o         |
|        ..       |
|      ..S        |
|     o o.        |
|   =o.+.         |
|. =++..          |
|o=++.            |
+-----------------+
```
Copy newly generated keys to pi.
```bash
ssh-copy-id -i ~/.ssh/id_pi-runner<EMAIL_ADDRESS>
```
Test the new key
```bash
ssh -i ~/.ssh/id_pi-runner<EMAIL_ADDRESS>
```

### Disable password login
```bash
# Edit ssh config
sudo nano /etc/ssh/sshd_config
# Rplace "#PasswordAuthentication yes" with "PasswordAuthentication no"
# Save and exit

# Restart ssh service
sudo service ssh restart
```
**Make sure you don't loose your keys as otherwise you can't access your pi any more!**

repository: kilpkonn/webstore-api

gha_language: Java

repo_name: kilpkonn/webstore-api


text:
# Restaurant Rating Prediction

A Machine Learning webapp.

## Description

- This is a webapp to predict the ratings of restaurants in bangalore.
- This uses Random Forest Classifier

## Aim / Goal

- This is said to be a intermediate level project in ineuron's internship portal and i wanted to get started with some projects and interships so, i thought of starting with this project.

## Skillset

- EDA
- Data Preprocessing
- Feature Engineering
- Model Building and Tuning
- Python Programming (backend)
- Web Development
- AWS Cloud skills (ec2 instances, s3 bucket)
- Cassandra Database
- Version control (git, github, dvc)

## Dataset

- Download the dataset for custom training.
    - https://www.kaggle.com/himanshupoddar/zomato-bangalore-restaurants
- Download a modified version with a primary key added by me.
    - https://drive.google.com/file/d/1rA3AZcptVCr54B84oW0gtO1igEttmK6r/view?usp=sharing

## Demo

[YouTube Video link](https://youtu.be/cpAEbemEo2U)

## Tech Stack

- Seaborn
- Matplotlib
- dtale
- DVC

## Installation

Requirements

- Python 3.8
- Cassandra 3.11
- Windows or ubuntu 20.04 (preferbly, setup Cassandra on dockers if working on windows)

## Deployment

The Deployment was done on aws ec2 instances.

What you need to do:
- setup cassandra database and push data onto it.
- create a s3 bucket and use it as intermediate in file sharing.
- setup the webapp and run it.

### Setting up the database
(Note: use 4GB of memory for a every instance you create to act as a node or cassnadra will stop right after it starts.)

- First install java

```bash
sudo apt update
sudo apt install openjdk-8-jdk -y
java -version
sudo update-alternatives --config java
```
- Make Java accessible, edit the .bashrc file by:

```bash
sudo nano ~/.bashrc
```
- Paste this line on the last line in the file and save it:
```bash
JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
```

- then run below line to apply the changes:
```bash
source ~/.bashrc
```

- Now, install and setup cassandra
```bash
sudo apt install apt-transport-https
wget -q -O - https://www.apache.org/dist/cassandra/KEYS | sudo apt-key add -
sudo sh -c 'echo "deb http://www.apache.org/dist/cassandra/debian 311x main" > /etc/apt/sources.list.d/cassandra.list'
sudo apt-get update
sudo apt-get install cassandra -y
```

- wait for half a minute or so for cassandra to start, then run to see if its running:
```bash
nodetool status
```

- Now, download and unzip the dataset:
( I have modified the original dataset to have a primary key column and changed the delimiter to '|')
```bash
sudo apt-get install unzip
wget --no-check-certificate -r 'https://docs.google.com/uc?export=download&id=1rA3AZcptVCr54B84oW0gtO1igEttmK6r' -O zomato.zip
unzip zomato.zip
```

- We will be using a python script to upload the csv file onto the cassandra database (Copy command and dsbulk come across 2 issues that is, firstly they have a field size limit and they tend to read more if not less columns, which i think is a delimiter issue so i just used python. The field size limit is easy to solve, you only have to change the .cqlshrc file but i couldn't solve the latter problem)
```bash
sudo apt install python3-pip
pip install cassandra-driver pandas
```

- Enter cqlsh shell by running:
```bash
cqlsh
```

- Now, we create a keyspace and table:
(Note: i am using a single node in this case but you can use multiple nodes and link them easily. You may find this video helpful: [YouTube video link](https://www.youtube.com/watch?v=3zhJyAwZkYo&t=876s))

```bash
create keyspace if not exists Data with replication = {'class' : 'SimpleStrategy', 'replication_factor':1};

Use Data;

CREATE TABLE if not exists Data.zomato (url text,address text,name text,online_order text,book_table text,rate text,votes int,phone text,location text,rest_type text,dish_liked text,cuisines text,approx_cost text, reviews_list text, menu_item text, listed_in_type text,listed_in_city text,id_no Bigint, primary key(id_no));
```
- Now, exit cqlsh shell and enter python shell by doing CRLT+Z or CRLT+X and running:
```bash
python3
```

- Run the below script to upload the data into cassandra db
```bash
from cassandra.cluster import Cluster
import csv
import pandas as pd

cluster = Cluster(['<IP_ADDRESS>'], port=9042)
session = cluster.connect()
session.execute("create keyspace if not exists Data with replication = {'class' : 'SimpleStrategy', 'replication_factor':1};")
session.execute('Use Data;')
with open('zomato.csv', 'r') as file:
    csv.field_size_limit(10000000)
    csv_reader = csv.reader(file, delimiter='|')
    next(csv_reader)
    for row in csv_reader:
        (url, address, name, online_order, book_table, rate, votes, phone, location, rest_type, dish_liked,cuisines,approx_cost,reviews_list, menu_item,listed_in_type,listed_in_city, id_no) = row
        session.execute("""INSERT INTO zomato ( url ,address, name, online_order, book_table, rate, votes, phone, location, rest_type, dish_liked,cuisines,approx_cost,reviews_list,menu_item, listed_in_type , listed_in_city, id_no) VALUES ( %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s,%s, %s, %s,%s, %s, %s);""", [url ,address, name, online_order, book_table, rate, int(votes), phone, location, rest_type, dish_liked,cuisines,approx_cost,reviews_list,menu_item, listed_in_type , listed_in_city, int(id_no)])
```

- after the process stops (about 3-5 minutes), run:
```bash
select count(*) from data.zomato;
```
It prints the number of rows in the zomato table.

- Now, when you want to export the table, just run this in the cqlsh shell
```bash
COPY data.zomato ( id_no , address , approx_cost , book_table , cuisines  , dish_liked ,  listed_in_city, listed_in_type, location, menu_item, name, online_order, phone, rate, rest_type, reviews_list, url, votes) TO 'export.csv' WITH HEADER = TRUE AND DELIMITER='|';
```

- then zip the file:
```bash
sudo apt-get install zip
zip export export.csv
```

- Now to upload the file to s3 bucket, install awscli

(Note: You will have to create a IAM role with access to s3 bucket and give that role the instances you are using. )

```bash
sudo apt-get install awscli
```

- Then you need your unique bucket name to upload the data:

```bash
aws s3 cp export.zip s3://UniqueBucketName
```

### Setting up the webapp
first upload your files to the instance.
Then, fullfill the requirements.

(Note: Use t2 small (2GB) memory if you intend to train it remotely)

- Do the installations:
```bash
sudo apt-get update
sudo apt install awscli
sudo apt-get install unzip
sudo apt install python3-pip -y
pip3 install -r requirements
```
- Go to the data_given directory and run the below to get the data from s3 bucket and unzip it.
You can just keep the file name as zomato instead of export from the start. i just didn't think of it at the time.
```bash
aws s3 cp s3://UniqueBucketName/export.zip .
unzip export.zip
mv "export.csv" "zomato.csv"
```

- Now, go to the main directory of our project and run our app:
```bash
python app.py
```

You can do the training either on the cloud or on your local system.
you have to run the files in the src folder one by one, i usually did it on the local system and used dvc to do so.

## Documentation

- [High Level Documents](https://drive.google.com/file/d/1EAOnpQhf3ap8X5ZOHQGU3NjqJa8umhp7/view?usp=sharing)
- [Low Level Documents](https://drive.google.com/file/d/1oNYMINswUHTthdt66PbtEtuaT4rJnlwj/view?usp=sharing)
- [Wireframe](https://drive.google.com/file/d/1gLoHLRzVcfGwWxG5kmx0x4f_U5lHpy_8/view?usp=sharing)
- [Report](https://docs.google.com/presentation/d/14Pmn4SR93L7fRnGJvNQfJuKAf8PURd94/edit?usp=sharing&ouid=105403021575418724386&rtpof=true&sd=true)

## Challenges

- Setting up cassandra and successfully using it was a big challenge and i spent about 10 days dealing with the problems i faced... some of the problems were because i developed it on windows at first i didn't know which version to use and how to install and run some of the versions without problems, with running it on remote system and with insertion of bulk data into cassandra.
- I spent a lot of time on features engineering and kept trying to come up with as many good features and new-new ideas but while i was doing feature selection and model training, i found out that one of the feature 'votes' was able to give 95% score on its own. Although the other features i made weren't useless on their own, they failed to improve the accuracy beyound 95% and it was very depressing as i had put so much time and effort into getting those features. so, initially after i made my model i didn't want to finish the project.

## What i Learnt

- Usage of cassandra DB
- AWS ec2, s3 bucket (uploading and download data), IAM roles.
- Usage of DVC, git, github.
- End to End development.
- Dockers (to setup cassnadra locally)

## Support

For support, email<EMAIL_ADDRESS>or contact me on linkedin.

## Usage
- You can use this project for further developing it and adding your work in it. If you use this project, kindly mention the original source of the project and mention the link of this repo in your report.
- I have provided the steps for deployment hoping it might help someone.

## 🚀 About Me
- I am a data science enthusiast.
- Currently studying 4th year in CSE
- I have some helpful content on kaggle as well so, check it out if interested

## 🔗 Links
[![kaggle](https://img.shields.io/badge/Kaggle-000?style=for-the-badge&logo=kaggle&logoColor=white)](https://www.kaggle.com/jackfroster)
[![linkedin](https://img.shields.io/badge/linkedin-0A66C2?style=for-the-badge&logo=linkedin&logoColor=white)](https://www.linkedin.com/in/syed-rahim-saqib-2505221b5/)

## License

[MIT](https://choosealicense.com/licenses/mit/)

## Author

- [Syed Rahim Saqib](https://www.github.com/Jack8861)

branch_name: refs/heads/main


text:
# API spec

Disclaimer: All calls are using the HTTP method GET, even if the requests are not idempotent (like adding a new favorite group).

## API Key

All calls use the API - key as get parameter in the form:

	?api_key=j90inhuf1qx4myb8tqo5otrlpdzEXAMPLE

**If missing, a 403 Response is sent**

## Export

	HOST/api/export

* Returns the non-user specific data as a sqlite DB file

## Timezone

	HOST/api/get_timezone

* Call only once per sync

## JSON App Texts

	HOST/api/get_strings

## Module Types

	HOST/api/get_module_types

## Module Status

	HOST/api/is_module_active

* **GET-Parameters:**

  * param=module_type_name

## get_terms - Get Privacy/Terms as HTML

    HOST/api/get_terms?api_key=xyz

* **Returns**

  * on success: HTML formatted content of the page, e.g. {"response":{"pagecontent":"
Foo
"}}
  * on error: 404 (Not Found)

## login - Get user id and token for user identified by email and password

* **GET-Parameter**

  * email - the email address of the user
  * password - cleartext password, encrypted via https

  * Example request:

<EMAIL_ADDRESS>---

* **Returns**

  * on success: JS property "**token**" and "userid" in JSON (application/json), e.g. {"response":{"token":"abc123", "userid":123}}
  * on error "Missing parameters": **400 (Bad Request)**
  * on error "wrong credentials or missing API key": **403 (Forbidden)**
  * on error "user token could not be generated": **500 (Internal Server Error)**

## add_favorite - Add an article to user's favorites

* **GET-Parameter**

    * token - the user token as received through the login call
    * article_id - the article to be added to the user's favorites

    HOST/api/add_favorite?api_key=KEY&token=abc&article_id=1

* **Returns**

        {
            "response": {
                "success": true
            }
        }

        * on error "Missing article ID": **400 (Bad Request)**
        * on error "Missing API token"/"Invalid API token": **403 (Forbidden)**

## remove_favorite - Remove an article from user's favorites

* **GET-Parameter**

    * token - the user token as received through the login call
    * article_id - the article to be removed from the user's favorites

    HOST/api/remove_favorite?api_key=KEY&token=abc&article_id=1

* **Returns**

        {
            "response": {
                "success": true
            }
        }

        * on error "Missing article ID": **400 (Bad Request)**
        * on error "Missing API token"/"Invalid API token": **403 (Forbidden)**

## add_favorite_group

* **GET-Parameter**

    * token - the user token as received through the login call
    * title - the title of the new group

* **Returns**

        {
            "response": {
                "success": true,
                "group_id": 1,
            }
        }

    HOST/api/add_favorite_group?api_key=KEY&token=abc&title=Hallo%20Welt

## remove_favorite_group

* **GET-Parameter**

    * token - the user token as received through the login call
    * group_id - the id of the group to be deleted

    HOST/api/remove_favorite_group?api_key=xyz&token=abc&group_id=1

## add_article_to_favorite_group

* **GET-Parameter**

    * token - the user token as received through the login call
    * group_id - the id of the group
    * article_id - the id of the article

    HOST/api/add_article_to_favorite_group?api_key=KEY&token=abc&group_id=1&article_id=1

## remove_article_from_favorite_group

* **GET-Parameter**

    * token - the user token as received through the login call
    * group_id - the id of the group
    * article_id - the id of the article

    HOST/api/remove_article_from_favorite_group?api_key=KEY&token=abc&group_id=1&article_id=1

## get_favorites - Get all favorites for logged in user

* **GET-Parameter**

    * token - the user token as received through the login call

* **Returns**

  * on success: JS property "**favoriteInfo**" in JSON, e.g.

        {
            "response": {
                "favoriteInfo": {
                    "allFavorites": [
                        274,
                        381,
                        221,
                        220
                    ],
                    "favoriteGroups": {
                        "Name der Gruppe": {
                            "id": 1,
                            "articles": [
                                521,
                                274
                            ],
                            "sharelink": "favorites/showgroup/5/91922800eb16af310683b5173f465b25"
                        }
                    }
                }
            }
        }

  * Minimal-Response:

        {
            "response": {
                "favoriteInfo": {
                    "allFavorites": [],
                    "favoriteGroups": {}
                }
            }
        }

  * on error "Missing API token"/"Invalid API token": **403 (Forbidden)**

## add_article - POST a new article

* **GET-Parameter**

    * token - the user token as received through the login call

    HOST/api/add_article?api_key=KEY&token=abc

* **POST-Body** - containing JSON representation of article

    {
        "article": {
            [...]
        }
    }

* **Returns**

* Positive Response:

    {
        "response": {
            "success": true,
            "article_id": 1,
            "images": [1,2,3]
        }
    }

* Negative Response:

    {
        "response": {
            "success": false,
            "article_id": null,
            "images": []
        }
    }

repository: bertelsmannstift/Beteiligungskompass

repo_name: bertelsmannstift/Beteiligungskompass


text:
---
title: 'Study Notes: Reading Introduction to CSS 2.1'
date: '2019-03-01'
---

Study notes by [tae](https://github.com/Ta2Rim), also posted [here](https://gist.github.com/Ta2Rim/8df3a47d3f50530e39d3c845c58f2ee9).

# Reading introduction to CSS 2.1 - Question

## What are the ways to include stylesheets to webpages?

CSS can be used with any structured document format.

1. HTML

- within HTML document (STYLE element)

```
<STYLE>
  h1 {color : red}
</STYLE>
```

- via an external style sheet (LINK element)

```
<LINK rel="stylesheet" href="app.css" type="text/css">
```

For maximum flexibility, the way that link to an exteral style sheet is better.

2. XML

- via an extenral style sheet (processing instruction)

```
  <?xml-stylehseet type="text/css" herf="app.css"?>
```

Unlike HTML, Element names in XML are case-sensitive. So a selector writen in lowercase is different from uppercase.

## How does CSS combine multiple stylesheets that apply to the same webpage?

When CSS combine multiple stylesheets, there would be a lot of confilcts between different values in CSS.
To resolve this problem, the rule determine the final presentation of document. Because CSS rule tries to influence only one of properties needed for rendering an HTML document.

## What are the steps a UA (browser) takes in order to apply styles to their underlying documents?

it's according to CSS processing model.

1. Parse the source document and create a document tree.
2. Identify the target media type. (e.g. print, screen, tty ...etc)
3. Retrieve all style sheets associated with the document that are specified for the target media type
4. Annotate every element of the document tree by assigning a single value to every property.
5. From the annotated document tree, generate a formatting structure.
6. Transfer the formatting structure to the target medium. (e.g. print the results, display them on the screen, render them as speech)

## Name a few strengths and constraints of CSS.

**Strengths (CIIR)**

- Compatibility

  CSS 2.1 user agent can understand CSS1 style sheet. and vice versa. Although it can't understand all of enhanced documents. but all content is presented.

- Isolation

  CSS let change the style sheet with little or no impact on the markup.

- Independence (to vendor, platform, device)

  CSS enable documents to remain vendor, platform, and device independent. and CSS 2.1 also allows authors to target a style sheet for a group of device.

- Richness

  Providing authors with a rich set of rendring effects.

**Constraints (LA)**

- Limited

  For all media, there is canvas that means 'the space where the formating structure is rendered'. The canvas is infinite for each dimension of the space. but in CSS established by user agent, User agent may render to a page impose width and height constraints.

- Abandonment

  In CSS rule, there's no more syntax for structure. only selector and declaration exist. So, in perspective of maintaining some style, CSS has weakness.

---

The more I study about CSS, the more I realize that CSS is amazing. Thanks for CSS, I can express what I imagined through CSS. I like CSS's richness very much. I'll show me to other people with my own website(with CSS).

---

we can comment or ask something or correct some mistakes... whatever reply on this markdown. thanks for reading! Let's study together, passionately!!! 😃

gha_language: JavaScript


text:
# SMS - Stock Management System

## Project Setup

### Requirements
- Python3+

### Steps
- Clone the repository
- Create a Python virtual env and install all dependencies
```shell script
$ python3 -m venv venv  # Create a Python virtual environment inside venv folder
$ source venv/bin/activate  # Activate virtual environment
$ pip install -r dev-requirements.txt  # Install all dependencies (dev)
# From now on you should always activate this environment when working on the project
```
- Create a database
```shell script
$ psql  # login to Postgres client
$ CREATE DATABASE dev_sms;  # create database named "dev_sms"

```
- Create a `.env` file and set the env vars following `env.example`
  - You'll need to set the database name you created in the previous step
  - Remember to set your email and password as Admin
```shell script
$ cat env.example > .env  # Copy env.example contents to a new .env file
```
- Run `flask deploy`
  - It will call the method `app.commands.deploy` which makes the database migrations, creates the Admin User, roles and the main Stock model instance.
- Run `flask run`
- Access `http://localhost:5000` and login with your admin account

repository: gems-uff/sms

gha_language: Python

repo_name: gems-uff/sms


text:
# Open Horizon Setup

This repository contains sample scripts to automatically setup nodes for [Open Horizon][open-horizon] as provided in the IBM Cloud.  Detailed [documentation][edge-fabric] for the IBM Cloud Edge Fabric is available on-line.  A Slack [channel][edge-slack] is also available.  You may create and publish your patterns to your organization.  Refer to the [examples][examples] available on GitHub.

You will need an [IBM Cloud][ibm-cloud] account and IBM MessageHub credentials available in the Slack [channel][edge-slack].

## Supported devices
A target device or virtual environment is required; either of the following are sufficient.

### VM - LINUX (Ubuntu) Virtual Machine
Download an Ubuntu [image][ubuntu-image] and start a new virtual machine, e.g. using [VirtualBox][virtualbox], with the CD/DVD image as the boot device; change networking from `NAT` to `Bridged`.  **Note**: Install the VirtualBox Extensions Pack.  Connect to VM using `ssh` or use the GUI to start a Terminal session.

### Rpi3B+ - RaspberryPi3+ with Raspbian Stretch
1. Download Raspbian [image][raspbian-image] for the RaspberryPi3 and flash a 32 Gbyte+ micro-SD card.  On macOS use [Etcher][etcher-io], **but** <ins>unset the option</ins> to `Auto un-mount on success`.
1. Create the file `ssh` in the root directory of the mounted SD-card; on macOS use `touch /Volumes/boot/ssh`.  This step will enable remote access using the `ssh` command with the default login `pi` and password `raspberry`.
1. Eject the SD-card (e.g. on macOS use `diskutil eject /Volume/boot`).
1. Insert uSD-card into a RPi3 and connect to _wired_ ethernet (or create appropriate `wpa_supplicant.conf` file in the root directory).

# A. Manual Installation
## Process
### Step 1 - Install Open Horizon
For either Ubuntu VM or Raspbian Raspberry Pi3 the software can be installed manually.  Log into the VM or RPi3 and run the commands below:

```
wget -qO - get.docker.com | sudo bash
```

```
sudo -s
APT_REPO=updates \
  && APT_LIST=/etc/apt/sources.list.d/bluehorizon.list \
  && PUBLICKEY_URL=http://pkg.bluehorizon.network/bluehorizon.network-public.key \
  && wget -qO - "${PUBLICKEY_URL}" | apt-key add - \
  && echo "deb [arch=armhf,arm64,amd64] http://pkg.bluehorizon.network/linux/ubuntu xenial-${APT_REPO} main" > "${APT_LIST}" \
  && apt-get update -y && apt-get install -y bluehorizon horizon horizon-cli
exit
```

It is recommended, but not required, to change the default `pi` password,  as well as identify the device with a unique name for use in testing (e.g. `test-rpi3-1`):

```
passwd pi
export DEVICE_NAME=test-rpi3-1
sudo sed -i "s|raspberrypi|${DEVICE_NAME}|" /etc/hosts
sudo sed -i "s|raspberrypi|${DEVICE_NAME}|" /etc/hostname
sudo hostname ${DEVICE_NAME}
```
The device will need to be rebooted for the name change to take effect.

### Step 2 - Configure for development / testing

If the device is to be used for development and testing it will need to be configured with the appropriate account, privileges, and change `sudo` policy for that user to not require a password:

```
export USERID=<your-userid>
sudo adduser ${USERID}
```

```
sudo addgroup ${USERID} sudo
sudo addgroup ${USERID} docker
```

```
sudo -s
echo "${USERID} ALL=(ALL) NOPASSWD: ALL" >  /etc/sudoers.d/010_${USERID}-nopasswd
chmod 400  /etc/sudoers.d/010_${USERID}-nopasswd
```

The **development host** (e.g. Apple iMac or MacBook) will also need to be configured with SSH credentials (n.b. `~/.ssh/`) which are then copied to the device from the host; run the following command as `<your-userid>` on the development host:

```
ssh-copy-id <device-name>.local # and enter password chosed previously
```

After credentials are established, the device may be used to test [services][service-md] and [patterns][pattern-md].  Refer to [`BUILD.md`][build-md].

[make-md]: https://github.com/dcmartin/open-horizon/blob/master/MAKE.md
[build-md]: https://github.com/dcmartin/open-horizon/blob/master/BUILD.md
[pattern-md]: https://github.com/dcmartin/open-horizon/blob/master/PATTERN.md
[service-md]: https://github.com/dcmartin/open-horizon/blob/master/SERVICE.md

# B. Network installation

Installations can be performed over the network when devices are discovered.  This technique is suitable for local-area network (LAN) deployments. Please refer to [these][network] instructions.

# C. System installation

System level installation modifies the operating system image boot sequence to install the Open Horizon software.  This technique is suitable for replication.  Please refer to [these][system] instructions.

# D. Horizon Addons

Add the repository [`https://github.com/dcmartin/hassio-addons`][dcm-addons] to the Add-on Store.  Install and start the following addons (n.b. both require `MSGHUB_API_KEY` to `listen` for Kafka messages):

+ [cpu2msghub][cpu2msghub-addon]: specifies the IBM published [cpu2msghub][cpu2msghub-pattern] pattern, which sends CPU load from `/sys/proc` and GPS location to a _private_ Kafka topic; optionally listens to the _private_ Kafka topic and publishes a JSON payload to topic `kafka/cpu-load` on designated MQTT server, e.g. `core-mosquitto`
+ [sdr2msghub][sdr2msghub-addon]: specifies the IBM published [sdr2msghub][sdr2msghub-pattern] pattern, which sends software-defined-radio (SDR) audio and GPS location to a _shared_ Kafka topic; optionally listens to the _shared_ Kafka topic and publishes a JSON payload to topic `kafka/sdr-audio` on designated MQTT server, e.g. `core-mosquitto`
  - Optional: Converts audio received into text using IBM Watson Speech-to-Text (STT) service.
  - Optional: Parses text into language using IBM Natural Language Understanding (NLU) service.

## Sample Output

![sdr2msghub sentiment](https://github.com/dcmartin/hassio-addons/raw/master/sdr2msghub/sdr2msghub_sentiment.png?raw=true "SDR2MSGHUB")
![cpu2msghub sentiment](https://github.com/dcmartin/hassio-addons/raw/master/cpu2msghub/cpu2msghub_cpu.png?raw=true "CPU2MSGHUB")

## Changelog & Releases

Releases are based on Semantic Versioning, and use the format
of ``MAJOR.MINOR.PATCH``. In a nutshell, the version will be incremented
based on the following:

- ``MAJOR``: Incompatible or major changes.
- ``MINOR``: Backwards-compatible new features and enhancements.
- ``PATCH``: Backwards-compatible bugfixes and package updates.

## Authors & contributors

David C Martin<EMAIL_ADDRESS>

[commits]: https://github.com/dcmartin/open-horizon/setup/commits/master
[contributors]: https://github.com/dcmartin/open-horizon/setup/graphs/contributors
[cpu2msghub-addon]: https://github.com/dcmartin/hassio-addons/tree/master/cpu2msghub
[cpu2msghub-pattern]: https://github.com/open-horizon/examples/tree/master/edge/msghub/cpu2msghub
[dcm-addons]: https://github.com/dcmartin/hassio-addons
[dcmartin]: https://github.com/dcmartin
[docker]: https://www.docker.com/
[edge-fabric]: https://console.test.cloud.ibm.com/docs/services/edge-fabric/getting-started.html
[edge-install]: https://console.test.cloud.ibm.com/docs/services/edge-fabric/adding-devices.html
[edge-slack]: https://ibm-cloudplatform.slack.com/messages/edge-fabric-users/
[etcher-io]: https://www.balena.io/etcher/
[examples]: https://github.com/open-horizon/examples
[ha-addons]: https://github.com/hassio-addons
[ha-home]: https://www.home-assistant.io/
[hassio-install]: https://www.home-assistant.io/hassio/installation/
[hassio-setup]: https://github.com/dcmartin/open-horizon/blob/master/setup/hassio-install.sh
[horizon-setup]: https://github.com/dcmartin/open-horizon/blob/master/setup/hzn-install.sh
[ibm-apikeys]: https://console.bluemix.net/iam/#/apikeys
[ibm-cloud]: http://cloud.ibm.com/
[ibm-registration]: https://console.bluemix.net/registration/
[issue]: https://github.com/dcmartin/open-horizon/setup/issues
[keepchangelog]: http://keepachangelog.com/en/1.0.0/
[network]: https://github.com/dcmartin/open-horizon/tree/master/setup/NETWORK.md
[open-horizon]: https://github.com/open-horizon
[raspbian-image]: https://www.raspberrypi.org/downloads/raspbian/
[releases]: https://github.com/dcmartin/open-horizon/setup/releases
[repository]: https://github.com/dcmartin/open-horizon/setup
[sdr2msghub-addon]: https://github.com/dcmartin/hassio-addons/tree/master/sdr2msghub
[sdr2msghub-pattern]: https://github.com/open-horizon/examples/tree/master/edge/msghub/sdr2msghub
[setup-readme]: https://github.com/dcmartin/open-horizon/blob/master/setup/README.md
[setupdir]: https://github.com/dcmartin/open-horizon/tree/master/setup
[system]: https://github.com/dcmartin/open-horizon/tree/master/setup/SYSTEM.md
[ubuntu-image]: http://releases.ubuntu.com/18.04.1/
[virtualbox]: http://www.virtualbox.org/

repository: lingarajonline/open-horizon

repo_name: lingarajonline/open-horizon


text:
# Javascript starter

This is a starter kit for Wemake Javascript course.

## Getting Started

### Installing

Be sure to have node-js installed.

Download the repository at [https://github.com/WeMakecc/js-01-starter-parcel-p5](https://github.com/WeMakecc/js-01-starter-parcel-p5), unzip and open a terminal in the project directory.

```
npm install
```

### Usage

```
npm start
```

A local version will now be running on [localhost:1234](http://localhost:1234)

gha_language: CSS


text:
---
title: GitLab CI
---

We'll walk you through the workflow of validating and importing your services using GitLab's CI Job functionality which will help you reliably bring your `effx.yaml` files into effx.

### Configure your Secret API key

You'll first need to configure a Variable within GitLab in order to use the CI/CD Job with effx.

1. Navigate to **Settings > CI / CD** for the repo

2. Jump to the section called **Variables** and choose **Add Variable**

3. On the **Add variable** screen, add `EFFX_API_KEY` as the Key and insert your **effx API key** into the Value field. You can find your API key in the effx platform by navigating to **Account Settings**. In addition, check both **Protect Variable** and **Mask Variable** options

![repo settings](/img/gitlab-add-variable.png)

4. Click **Add variable** and you're set!

### Set up your .gitlab-ci.yml file

If you've made it this far, you're probably familiar with setting up a `.gitlab-ci.yml` file. Below is a recommendation if the file is empty, but feel free to adjust as you feel necessary.

```yaml title=".gitlab-ci.yml"
---
# Lints all definitions on every commit
# Syncs all definitions on every commit to master
image: ubuntu:latest

before_script:
  - curl -Lo /tmp/effx https://effx.run/effx-cli/releases/latest/effx-cli_Linux_x86_64
  - sudo install /tmp/effx /usr/local/bin

lint-all:
  stage: test
  script:
    - effx lint -d .

sync-all:
  stage: deploy
  variables:
    EFFX_API_KEY: ${EFFX_API_KEY}
  script:
    - effx sync -d .
  only:
    - master

# Add events to your workflow (pro-tier)
deploy-services:
  stage: deploy
  variables:
    EFFX_API_KEY: ${EFFX_API_KEY}
  script:
    - effx event -k ${EFFX_API_KEY} --title "Deployment Started" --message "Deploying backend services" --tag "type:deploy"
    # Below are ideas for different types of events you could send based upon the exit code of your continuous deployment system
    #
    # For example, if your deploy succeeded, you could send an event like the one below:
    # - effx event -k ${EFFX_API_KEY} --title "Deployment Finished" --message "Deployed backend services" --tag "type:deploy"
    # If it failed:
    # - effx event -k ${EFFX_API_KEY} --title "Deployment Failed" --message "Failed backend services" --tag "type:deploy"
  only:
    - master
```

:::note
If you use a default branch other than `master`, e.g. `main`, please update the config appropriately.
:::

### Push to your default branch

To complete the process, push the new `.gitlab-ci.yml` file to your main/master branch.

Now, whenever you merge code into the main branch for this repository, a job to lint and sync services to effx will run. This will find all `effx.yaml` files in the repo and lint and sync them accordingly.

You can view status by going to **CI/CD > Jobs** in the repository's navigation menu.

repository: effxhq/rammahgon

repo_name: effxhq/rammahgon


text:
# Challenge-3

**Level**: 2

**Description**: Alice wants to send the same message to 4 different people. So, for this he generates 4 different public key pairs, encrypts the same message for 4 people using these public key pairs, generates the corresponding ciphertexts and sends each ciphertext to each person. We have the public key parameters for each person. Find the vulnerability, and find out what Alice is sending!

**Points**: 20

**Documentation reference for libraries used**:
1. pycrypto: https://www.dlitz.net/software/pycrypto/api/2.6/
2. gmpy2: https://gmpy2.readthedocs.io/en/latest/

repository: vanshdevgan/Crypton

repo_name: vanshdevgan/Crypton


text:
# PigLatinTranslate

Pig Latin is a made-up children's language that's intended to be confusing. It obeys a few simple rules (below) but when it's spoken quickly it's really difficult for non-children (and non-native speakers) to understand.

Rule 1: If a word begins with a vowel sound, add an "ay" sound to the end of the word.

Rule 2: If a word begins with a consonant sound, move it to the end of the word, and then add an "ay" sound to the end of the word.

See <http://en.wikipedia.org/wiki/Pig_latin> for more details.

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'pig_latin_translate'
```

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install pig_latin_translate

## Usage

TODO: Write usage instructions here

## Contributing

1. Fork it ( https://github.com/[my-github-username]/pig_latin_translate/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request


text:
+++
Title = "Sponsor"
Type = "event"
Description = "Sponsor devopsdays Galway 2019"
+++

We greatly value sponsors for this open event.  If you are interested in sponsoring, please drop us an email at [{{< email_organizers>}}].

Join the community

devopsdays is a self-organizing conference for practitioners that depends on sponsorships. We do not have vendor booths, sell product presentations, or distribute attendee contact lists. Sponsors have the opportunity to have short elevator pitches during the program and will get recognition on the website and social media before, during and after the event. Sponsors are encouraged to represent themselves by actively participating and engaging with the attendees as peers. Any attendee also has the opportunity to demo products/projects as part of an open space session.

Gold sponsors get a full table and Silver sponsors a shared table where they can interact with those interested to come visit during breaks. All attendees are welcome to propose any subject they want during the open spaces, but this is a community-focused conference, so heavy marketing will probably work against you when trying to make a good impression on the attendees.

The best thing to do is send engineers to interact with the experts at devopsdays on their own terms.

Sponsoship Packages

                Benefits (prices ex VAT)

                Comunity
(free)

                Bronze
(€ 500)

                Silver
(€ 1,500)

                Gold
(€ 3,000)

              Tickets included

              1
              2
              4

              Space in `Swag Bag` for promotional item

              ✔
              ✔
              ✔

              Logo on interval rotating slide show
              Shared
              Shared
              Shared
              Dedicated

              Logo on DevOpsDays Galway 2019 website
              ✔
              ✔
              ✔
              ✔

              Logo on email communication

              ✔
              ✔

              Sponsor table space
              Shared table for promotional material
              Pop-up 1 space + shared table for promotional material
              Dedicated
Half table (approx 1m) + socket
              Dedicated
+socket
Full table (approx 2m) + socket

              Audience address pitch

              2 min

        In addition to the above sponsorship packages, devopsdays Galway 2019 is open to focused sponsorship of items such as lanyards, accessibility services, morning break snacks, lunch, tea break snacks, and evening social event, which will be appropriately recognised on signage.
        Send email to {{< email_organizers>}}

repository: rchillard/devopsdays-web

gha_license_id: NOASSERTION

repo_name: rchillard/devopsdays-web