Skip to content

Instantly share code, notes, and snippets.

View jesty's full-sized avatar

Davide Cerbo jesty

View GitHub Profile
@jesty
jesty / OtherActivity.java
Last active July 6, 2023 06:36
Share cookies between WebView and OkHttpClient 3 / Retrofit 2. In the example I did the login on a web page in a WebView component and then I used the cookie to invoke a service from an activity
//Setup the client
OkHttpClient client = new OkHttpClient.Builder()
.cookieJar(new CookieJar() {
@Override
public void saveFromResponse(HttpUrl url, List<Cookie> cookies) {
}
@Override
@jesty
jesty / pom.xml
Created October 7, 2016 22:17
Configuring Keycloak Tomcat Adapter in Maven Tomcat adapter. You must edit your plugin configuration in pom.xml, add a context.xml file with the code above and enjoy wit mvn tomcat:run
<!-- pom.xml --->
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<path>/memento</path>
<port>9999</port>
<contextFile>src/main/webapp/META-INF/context.xml</contextFile>
@jesty
jesty / WebConfiguration.java
Created June 16, 2016 07:37
Use H2 console with Spring Boot
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@Configuration
public class WebConfiguration extends WebSecurityConfigurerAdapter
{
@Override
protected void configure(HttpSecurity http) throws Exception
@jesty
jesty / restart.sh
Last active May 30, 2016 21:06
Restart service if an url doesn't works (doesn't return 200 http status). In this example I restart an Apache Tomcat service.
#!/bin/bash
#service monitoring
#check if the url responds 200 in 60 seconds
timeout -s SIGTERM 60 curl -I https://youurl.com | grep '200 OK'
#> /dev/null
a=$(echo $?)
if test $a -ne 0
then
echo "tried to restart" > laststatus.txt
echo "restart tomcat service"
@jesty
jesty / DotNotationToMap.java
Last active February 26, 2016 16:46
This is a quick and dirty utility class to transform some keys that use dot notation (i.e. properties file keys) to a hierarchical structure like a java.util.Map. Usefull to transform a properties file to a json
import java.util.HashMap;
import java.util.Map;
/*
* This is a quick and dirty utility class to transform some keys
* that use dot notation (i.e. properties file keys) to a hierarchical
* structure like a java.util.Map.
* Usefull to transform a properties file to a json.
*/
public class DotNotationToMap
@jesty
jesty / Planner.jsx
Created November 5, 2015 21:09
React Big Calendar (https://github.com/jquense/react-big-calendar) is a fantastic outlook / gmail style calendar. Unfortunately hasn't a good documentation and example code. There is one inspired from Example folder :)
import React from 'react';
import { Glyphicon, Col, Row } from 'react-bootstrap';
import BigCalendarCSS from 'react-big-calendar/lib/css/react-big-calendar.css';
import BigCalendar from 'react-big-calendar';
import Moment from 'moment';
import Events from 'Events.jsx'; // https://github.com/jquense/react-big-calendar/blob/master/examples/events.js
export default class Planner extends React.Component {
constructor(props, context)
{
@jesty
jesty / If.jsx
Last active November 2, 2015 10:37
A simple widget to define conditions (if) in JSX
import React from 'react';
export default class If extends React.Component {
constructor(props)
{
super(props);
this.state = {condition: this.props.condition};
}
@jesty
jesty / pom.xml
Last active August 29, 2015 14:28
Execute NPM during a Maven build.
<!-- In my JEE project I use REACT with Babel and Webpack and I must build the javascript files before prepare the WAR.
I have also configure webpack.config.js to build in a folder under my web application, e.g.:
var DIST_PATH = path.resolve(ROOT_PATH, '../src/main/java/webapp/js/react');
To setup REACT inside my project I used https://github.com/gesposito/bare-webpack
-->
<project>
<build>
@jesty
jesty / sameDirection.js
Last active August 29, 2015 14:23
Route with same direction
/*
* Starting from two route, this algorithm, verify if they are the same direction.
* The computeHeading function is defined in https://gist.github.com/jesty/7b2a8e31d56c13a6adff
*/
var sameDirection = function(startA, endA, startB, endB){
var headingA = computeHeading(startA, endA);
var headingA = computeHeading(startB, endB);
return Math.abs(headingA - headingA) < 45
};
@jesty
jesty / computeHeading.js
Last active September 26, 2019 02:59
Compute heading
/*
* A heading is defined in degrees from true north, where headings are measured clockwise from true north (0 degrees).
* The parameter for this function are two array that identifies a geo point with latitude at position 0 and longitude
* at position 1.
* This function is similar to https://developers.google.com/maps/documentation/javascript/geometry. I developed because
* I need it on Meteor server side.
* The result is a value between -180 and 180.
*/
var computeHeading = function (start, end){
var lat1 = start[0]*Math.PI/180;