Skip to content

Instantly share code, notes, and snippets.

View Kamilnaja's full-sized avatar
💭
🐍🔥

Kamil Naja Kamilnaja

💭
🐍🔥
View GitHub Profile
@Kamilnaja
Kamilnaja / index.js
Created April 13, 2017 20:33
login to mysql from express.app
var express = require('express');
var http = require('http');
var mysql = require('mysql');
var app = express();
var connection = mysql.createConnection({
host: 'localhost',
user: 'root',
password: '',
database: 'heroes'
@Kamilnaja
Kamilnaja / index.js
Last active April 16, 2017 13:07
module pattern - self invoced function
var myModule = {
animals: ['dog', 'cat', 'bird'],
addNewElement: function (newAnimal) {
var elementToAdd;
if (typeof newAnimal !== 'string') {
elementToAdd = document.querySelector('#animal').value();
} else {
elementToAdd = newAnimal;
}
@Kamilnaja
Kamilnaja / module - return some methods outside
Created April 16, 2017 13:22
module - return some methods outside
var ourModule = (function(){
var _animals = ['dog', 'cat', 'bird'];
var _addNewElement = function (newAnimal) {
var elementToAdd;
if (typeof newAnimal !== 'string') {
elementToAdd = document.querySelector('#animal').value();
} else {
elementToAdd = newAnimal;
}
var myInfo = "<p>My Name is {{name}} and I live at {{street}} in {{city}}, {{state}}</p>";
var template = Handlebars.compile(myInfo);
var data = template({name: "Derek", street: "123 main", city: "Lublin", state: "Warsaw shore"});
document.getElementById("kamilData").innerHTML += data;
<div id="quoteData"></div>
<script id="quote-template" type="text/x-handlebars-template">
<h3>Favorite {{name}} Quotes</h3>
<ol>
{{#each quotes }}
<li>{{quote}}</li>
{{/each}}
</ol>
</script>
<script>
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
// Typical action to be performed when the document is ready:
console.log(xhttp.responseText);
}
};
xhttp.open("GET", "json.json", true);
xhttp.send();
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $http) {
$http.get('users.json')
.then(function(response) {
$scope.myUsers = response.data;
console.log($scope.myUsers.people[1].name);
})
});
@Kamilnaja
Kamilnaja / Fiter items by name ANG2.ts
Last active May 6, 2017 11:27
Filter items by the name. Based on Net Ninja Tutorial
//inside template
<label>Filtruj po rasie</label>
<input type="text" name="filter" [(ngModel)]="term"/>
</form>
<div
*ngFor="let dog of dogs | filter:term;
let i = index"
class="puppy-wrapper"
(click)="onSelect(dog)"
@Kamilnaja
Kamilnaja / angular2 - choose item and open with more info
Created May 6, 2017 13:58
angular2 - choose item and open with more info
export class AppComponent implements OnInit {
herbs = [];
selectedHerb;
constructor(private _herbService: HerbsService){}
ngOnInit() {
this._herbService.getHerbs()
.subscribe(resHerbsData => this.herbs = resHerbsData);
}