Skip to content

Instantly share code, notes, and snippets.

Avatar
😷

Samuel samuelstein

😷
View GitHub Profile
@samuelstein
samuelstein / Ubuntu_Aerial.md
Last active Nov 27, 2016 — forked from Dhertz/Ubuntu_Aerial.md
Quick overview of how to get Apple's new TV screensavers working on most linux systems.
View Ubuntu_Aerial.md

Using Apple’s Aerial Screensavers on Ubuntu After coming across the [Aerial] (https://github.com/JohnCoates/Aerial) screensavers for Mac, and installing them, I decided that I had had enough of the graphics-demos of my Ubuntu Precise system. I hope to provide a simple guide on how to add them to your setup as well.

First, you need to install xscreensaver (for example with aptitude, but your distro should have it):

sudo apt-get install xscreensaver
@samuelstein
samuelstein / ColorHelper.java
Last active Mar 23, 2017
Convert RGB triplet to HEX
View ColorHelper.java
public static String toHexString(short[] triplet) {
return "#" + Integer.toHexString(new java.awt.Color(triplet[0], triplet[1], triplet[2]).getRGB()).substring(2);
}
@samuelstein
samuelstein / MailHelper.java
Created Mar 23, 2017
Generates mail like: name.surname@example.com
View MailHelper.java
public static String generateMail(String name, String surname) {
String[] searchList = {"ä", "ö", "ü", "ß"};
String[] replaceList = {"ae", "oe", "ue", "ss"};
String mailAddress = StringUtils.defaultIfBlank(StringUtils.lowerCase(name, Locale.GERMAN), "vorname") + "." + StringUtils.defaultIfBlank(StringUtils.lowerCase(surname, Locale.GERMAN), "nachname");
mailAddress = mailAddress.replace(" ", "-");
mailAddress = StringUtils.replaceEachRepeatedly(mailAddress, searchList, replaceList);
return StringUtils.stripAccents(mailAddress) + Constants.DEFAULT_MAIL_DOMAIN;
}
@samuelstein
samuelstein / HTTPSRedirectFilter.java
Created Nov 14, 2017
HTTPS Redirect filter for play framework (>=2.5)
View HTTPSRedirectFilter.java
package utils.filters;
import akka.stream.Materializer;
import play.Configuration;
import play.mvc.Filter;
import play.mvc.Http;
import play.mvc.Result;
import javax.inject.Inject;
import java.util.concurrent.CompletionStage;
@samuelstein
samuelstein / jenkins-seed.groovy
Created Feb 7, 2018
Jenkins Seed job for Gitlab projects
View jenkins-seed.groovy
// jenkins job dsl plugin is required!
// This job will be run through the gitlab projects (except user owned ones) and generate jenkins jobs with maven goal. if there should be no job generated, then the label 'nojob' must be set in repository config.
// reads projects from gitlab and creates jobs
def gitUrl = '$URL'
def privateToken = '$TOKEN'
def allowedNamespaces = ['product', 'innovation']
def reposToIgnoreTag = 'nojob'
def jobNames = []
@samuelstein
samuelstein / clearView.groovy
Created Oct 23, 2018
Clear jenkins view with jobs
View clearView.groovy
import hudson.model.ListView
import jenkins.model.*
//Parameters: In case you are running this outside Scriptler, please uncomment and fill the following line.
view_name = "ViewName";
vc = Jenkins.instance.getView(view_name).getOwner();
v = vc.getView(view_name);
//delete jobs belonging to the view
View FontAwesomeOffline.java
/**
* This is a wrapper class that registers the font awesome .ttf included in the package.
* ControlsFX loads this font dynamically at run time from a CDN. Thus, it works only if Internet
* connection is available
* .
* This class registers an included version of the font. The {@link #init()} method should be called
* during the initialization procedure of the application such that the font is available early.
*
* @author albrecht
*/
View FileWatcher.java
import model.IFileWatchListener;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.IOException;
import java.nio.file.*;
import java.util.ArrayList;
import java.util.List;
public class FileWatcher extends Thread {
@samuelstein
samuelstein / generic_list_gson.java
Created Oct 23, 2018
Deserialize generic list with gson
View generic_list_gson.java
Type listType = new TypeToken<ArrayList<YourClass>>(){}.getType();
List<YourClass> yourClassList = new Gson().fromJson(jsonArray, listType);
@samuelstein
samuelstein / SeleniumHelper.java
Created Nov 18, 2020
HTTP Requests with Selenium
View SeleniumHelper.java
public ResponseEntity<String> doJsonRequest(HttpMethod httpMethod, String path, Object body) throws URISyntaxException {
RestTemplate restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory());
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.add(COOKIE, getWebdriver().manage().getCookieNamed(YOUR_APP_COOKIE_NAME).toString());
headers.setAccept(List.of(MediaType.APPLICATION_JSON, MediaType.TEXT_HTML));
var request = new HttpEntity<>(body, headers);
return restTemplate.exchange(new URI("http", null, hostIpAddress, port, path, null, null), httpMethod, request, String.class);