Skip to content

Instantly share code, notes, and snippets.

View mrWinston's full-sized avatar

Marius Schulz mrWinston

  • Red Hat
  • Rostock, Germany
View GitHub Profile
@mrWinston
mrWinston / serialize.java
Last active October 21, 2015 15:10
Java Serializing Object to File #java #serialization #file #stream #writing
/* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://www.wtfpl.net/ for more details.
*/
try{
Object o = new Object();
@mrWinston
mrWinston / Deserialize.java
Last active October 21, 2015 15:10
Java Deserializing from File #java #serialization #file #stream
/* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://www.wtfpl.net/ for more details.
*/
try{
FileInputStream fileIn = new FileInputStream("object.ser");
ObjectInputStream in = new ObjectInputStream(fileIn);
@mrWinston
mrWinston / privMethInv.java
Last active October 21, 2015 15:10
Java Private Method Invokation #java #private #reflection
/* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://www.wtfpl.net/ for more details.
*/
try {
Method m = Object.class.getDeclaredMethod("myPrivateMethod", String.class, Serializable[].class, MyParameterObject.class)
m.setAccessible(true);
@mrWinston
mrWinston / MergeSort.java
Last active August 29, 2015 14:23 — forked from louisbros/MergeSort.java
Merge Sort Class #Sort #java #merge #comparable
package com.test;
import java.util.ArrayList;
import java.util.List;
public class MergeSort<T extends Comparable<T>> {
public void sort(List<T> values){
mergeSort(0, values.size() - 1, values, new ArrayList<T>(values));
}
@mrWinston
mrWinston / SingletonEnum.java
Last active July 13, 2016 13:47
Java Singleton by Enum #enum #singleton #pattern #design
/* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://www.wtfpl.net/ for more details.
*/
public enum EnumSingleton {
INSTANCE;
@mrWinston
mrWinston / FuturesConcurrency.java
Last active October 6, 2017 12:06
Java Futures usage #java #future #concurrency #multithreading #communication
/* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://www.wtfpl.net/ for more details.
*/
/**
* Executes Multiple futures
*
*/
@mrWinston
mrWinston / post.java
Last active October 24, 2022 09:10
Send a Post Request #java #http #post #curl
/**
* Example taken from http://www.mkyong.com/java/how-to-send-http-request-getpost-in-java/
*
**/
private static void sendPost() throws Exception {
String url = "https://www.sampleURL.example";
URL obj = new URL(url);
HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();
@mrWinston
mrWinston / fast_atom_open.sh
Last active October 21, 2015 15:09
opens a file in the atom-editor and raises the window #script #shell #dumbstuff
#!/bin/bash
# This program is free software. It comes without any warranty, to
# the extent permitted by applicable law. You can redistribute it
# and/or modify it under the terms of the Do What The Fuck You Want
# To Public License, Version 2, as published by Sam Hocevar. See
# http://www.wtfpl.net/ for more details.
# raise the window which has the string "Atom" in its title but is not chrome and switch to its workspace
wmctrl -ai $(wmctrl -l | grep Atom | grep -iv chrome | cut -b-10)
@mrWinston
mrWinston / sshFileAccess.sh
Last active October 21, 2015 14:13
Load a file via scp and open in your favourite editor. afterward, write the file back over scp to the server. #bash #scp #ssh #utility
#!/bin/bash
# This program is free software. It comes without any warranty, to
# the extent permitted by applicable law. You can redistribute it
# and/or modify it under the terms of the Do What The Fuck You Want
# To Public License, Version 2, as published by Sam Hocevar. See
# http://www.wtfpl.net/ for more details.
#some constants
@mrWinston
mrWinston / wtfplHeaderShell
Last active February 2, 2016 11:57
License Python-like #wtfpl #license #fuck ##
# This program is free software. It comes without any warranty, to
# the extent permitted by applicable law. You can redistribute it
# and/or modify it under the terms of the Do What The Fuck You Want
# To Public License, Version 2, as published by Sam Hocevar. See
# http://www.wtfpl.net/ for more details.