Skip to content

Instantly share code, notes, and snippets.

View Kamilnaja's full-sized avatar
💭
🐍🔥

Kamil Naja Kamilnaja

💭
🐍🔥
View GitHub Profile
@Kamilnaja
Kamilnaja / angular.component.spec.ts
Created March 24, 2019 12:30
Angular test component with mock service, that uses http
import { async, TestBed } from '@angular/core/testing';
import { Observable, of } from 'rxjs';
import { AppComponent } from './app.component';
import { HerbsService } from './herbs.service';
import { RouterTestingModule } from '@angular/router/testing';
class MockService {
mockRespone = {
data: [
{ id: 1, name: 'hello' },
@Kamilnaja
Kamilnaja / gist:e510241810f005b8bd7bde5e39c2f67a
Created February 22, 2019 23:47
Python_do_something_with_every_second.py
string = "How good is have account on StackOverflow and create new posts"
def odd(data):
idx, el = data
return el if idx % 2 == 0 else el + "\n"
print(" ".join(list(map(odd, list(enumerate(string.split(" ")))))))
@Kamilnaja
Kamilnaja / array.range.js
Created February 17, 2019 23:55
array range js
Array.prototype.range = function(start, stop) {
let d = [];
for (let i = start; i <= stop; i++) {
d.push(i);
}
return d;
}
@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}))
)
@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 / 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 / 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
function Person(first, last, age, gender, interests) {
this.name = {
first,
last
};
this.age = age;
this.gender = gender;
this.interests = interests;
}
// declare
@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;
@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
}