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 / 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();
@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:”john@example.com”},
@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 / 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 / atomikos_jms.java
Last active February 28, 2022 07:15
Spring Boot JTA Atomikos & JMS configuration
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;
@tyb
tyb / common_module_DepensOn_usage.java
Last active July 25, 2019 11:00
common module of multiple services: after environments set use DependsOn
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;
@tyb
tyb / jackson_templates.java
Last active July 23, 2019 04:55
json object deserialization/unmarshalling to java object(mainly array/list) with Jackson
//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
@tyb
tyb / print_map.java
Created July 22, 2019 09:47
Pretty-print a Map in Java
//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));
@tyb
tyb / article_react_component.jsx
Created June 19, 2019 11:43
react non semantic component, making div a component instead of li
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">
@tyb
tyb / bootstrap_alert.html
Created June 18, 2019 08:32
bootstrap card - index
<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">