This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
You could check the url of the request to prevent an infinite loop. Also instead of returning the config directly you could return a promise that resolves with it so you can wait until you have a valid token. e.g. | |
{ | |
request: function(config) { | |
if(config.url != 'my/refresh/url') { | |
var promiseToHaveValidToken; | |
var expiry = new Date($window.sessionStorage['userInfo-tokenexpiry']); | |
var now = new Date(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
We will rewrite the JavaScript array map function in a functional manner. | |
function map(fn) { | |
return function(arr) { | |
return Array.prototype.map.call(arr, fn) | |
} | |
} | |
map(function(x) {return x * x}) ([1, 2, 3]) //==>> [ 1, 4, 9 ] | |
Notice that the arguments are flipped. The function comes first then the array. Also we used Array.prototype.map.call instead of just calling arr.map. This is so that we can use our map function with array like objects, arguments and DOMNodeList. | |
Say you wanted to get all the emails from a list like this in an array. | |
var people = [ {name:”John”, email:”john@example.com”}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.xxx.common.config; | |
import com.xxx.common.util.CommonReqParams; | |
import com.xxx.common.util.RestInterceptor; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.Configuration; | |
import org.springframework.context.annotation.Scope; | |
import org.springframework.context.annotation.ScopedProxyMode; | |
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; | |
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.xxx.common.config; | |
import com.xxx.common.util.HeaderRequestInterceptor; | |
import org.apache.cxf.common.util.CollectionUtils; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.Configuration; | |
import org.springframework.http.client.ClientHttpRequestFactory; | |
import org.springframework.http.client.ClientHttpRequestInterceptor; | |
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; | |
import org.springframework.web.client.RestTemplate; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.xxx.common.config; | |
import com.atomikos.icatch.config.UserTransactionServiceImp; | |
import com.atomikos.icatch.jta.UserTransactionImp; | |
import com.atomikos.icatch.jta.UserTransactionManager; | |
import net.sf.ehcache.transaction.manager.TransactionManagerLookup; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.beans.factory.annotation.Value; | |
import org.springframework.boot.context.properties.EnableConfigurationProperties; | |
import org.springframework.context.annotation.Bean; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.xxx.common.util; | |
import com.atomikos.icatch.config.UserTransactionServiceImp; | |
import org.springframework.beans.factory.InitializingBean; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.core.env.Environment; | |
import org.springframework.stereotype.Component; | |
import java.util.Arrays; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//jackson mapper.readValue - json to java object | |
@RequestMapping(value="/newPost", method = RequestMethod.POST, produces="application/json", consumes = "application/json") | |
@ResponseBody | |
public ResponseEntity newPost(@RequestBody String body) throws Exception { | |
ObjectMapper mapper = new ObjectMapper(); | |
TypeReference<HashMap<String,Object>> typeRef = new TypeReference<HashMap<String,Object>>() {}; | |
HashMap<String,Object> map = mapper.readValue(body, typeRef); | |
} | |
//jackson - json to object |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//as json | |
new Gson().toJson(map) | |
//as json | |
ObjectMapper mapper = new ObjectMapper(); | |
mapper.writerWithDefaultPrettyPrinter().writeValueAsString(object); | |
//as json | |
Map<String, Object> stats = ...; | |
System.out.println(new JSONObject(stats).toString(2)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Article = (props) => { | |
// Notice: <li>s are gone | |
return <div class="article"> | |
<h2 class="article__title">{ props.title }</h2> | |
{ /* ... */ } | |
</div>; | |
} | |
const ArticleList = (props) => { | |
return <div class="articles"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="chatEkrani"> | |
<div class="row"> | |
<div id="mesajAlani bg-white" class="col-md-12"> | |
<div class="d-flex"> | |
<div class="alert alert-dark" role="alert"> | |
<b>@kizildas</b> Bu mesaj karşı taraftan geldi! | |
</div> | |
</div> | |
<div class="d-flex justify-content-end"> | |
<div class="alert alert-info" role="alert"> |
NewerOlder