Skip to content

Instantly share code, notes, and snippets.

View tyb's full-sized avatar
🤓
I may be slow to respond.

Taha Yavuz Bodur tyb

🤓
I may be slow to respond.
View GitHub Profile
@tyb
tyb / RestTemplateConfig.java
Created July 25, 2019 11:07
RestTemplateConfig
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;
@tyb
tyb / RestInterceptorConfig.java
Last active July 25, 2019 12:19
moving/transferring common request parameters between rest calls
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;
@tyb
tyb / 1607299168.txt
Created December 6, 2020 23:59
Created with Copy to Gist
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:”[email protected]”},
@tyb
tyb / jsMapImplementation.js
Created December 7, 2020 21:01
Created with Copy to Gist
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();