Skip to content

Instantly share code, notes, and snippets.

View Kamilnaja's full-sized avatar
💭
🐍🔥

Kamil Naja Kamilnaja

💭
🐍🔥
View GitHub Profile
@Kamilnaja
Kamilnaja / Observable.ts
Last active December 10, 2017 22:56
Observable in angular2
import { Observable } from "rxjs/Observable";
import { Injectable } from "@angular/core";
import { Http, Response } from "@angular/http";
import 'rxjs/add/operator/map';
@Injectable()
export class HttpClient {
constructor(
public http: Http
@Kamilnaja
Kamilnaja / app.js
Created December 17, 2017 18:46
angularjs $http example with factory
var app = angular.module('plunker', []);
app.factory('myService', function($http) {
return {
async: function() {
return $http.get('test.json'); //1. this returns promise
}
};
});
angular.module("my-app", ['dx', 'ngFileSaver'])
.controller("app-ctrl", ['$scope', '$http', function ($scope, $http) {
$scope.downloadPDF = function downloadPDF() {
$http({
url: 'http://localhost:3000/data',
method: 'GET',
})
.then((res) => {
console.log(res.data.lorem);
$scope.pdf = 'data:application/octet-stream;base64,' + res.data.lorem;
@Kamilnaja
Kamilnaja / MyClass.java
Created October 16, 2018 13:48
Spring - return xml data from string
@ResponseBody
@RequestMapping(
method = RequestMethod.GET,
value="test",
produces = MediaType.APPLICATION_XML_VALUE
)
public ResponseEntity<String>testXML(){
return ResponseEntity.ok("<xml></xml>); // inside use string creating xml data
}
@Kamilnaja
Kamilnaja / ArticleControllerTest.java
Created November 18, 2018 13:24
Test for json content in spring boot
package com.mycompany.myapp.web.rest.controller;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.mycompany.myapp.models.Article;
import com.mycompany.myapp.repository.ArticleRepository;
import com.mycompany.myapp.service.ArticleService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
function Person(first, last, age, gender, interests) {
this.name = {
first,
last
};
this.age = age;
this.gender = gender;
this.interests = interests;
}
// declare
@Kamilnaja
Kamilnaja / excusemewtf.js
Last active January 19, 2019 17:29
set timeout on for loop
/* The goal is to create function, that displays in console numbers from 0 to 9. After every number, we want little timeout.*/
// this only prints 10 ten times
for (let i = 0; i < 10; i++) {
setTimeout(() => {
console.log(i);
}, i * 1000)
}
//with arrow fn, also doesn't work
@Kamilnaja
Kamilnaja / vscode keybindings
Last active March 20, 2019 17:53
Keybindings for vscode for better workflow
// super awesome keybindings for proffesionals
[
// prevent quiting app when type
{
"key": "ctrl+q",
"command": "-workbench.action.quit"
},
// add new file when focused on sidebar
{
"key": "ctrl+n",
@Kamilnaja
Kamilnaja / angular.service.ts
Created February 3, 2019 13:22
AngularHandleError
this.http
.get(url)
.subscribe(
result => {
this.dataStore.listItems = result;
this._listItems.next(result);
},
error => {
console.log('error');
},
@Kamilnaja
Kamilnaja / doubleevery.js
Created February 15, 2019 16:54
double price property in js obj
let products = [
{ name: "Hat", price: 24.5, stock: 10 },
{ name: "Kayak", price: 289.99, stock: 1 },
{ name: "Soccer Ball", price: 10, stock: 0 },
{ name: "Running Shoes", price: 116.50, stock: 20 }
];
console.log(
products.map(item => ({name: item.name, price: item.price * 2, stock: item.stock}))
)