Skip to content

Instantly share code, notes, and snippets.

View ryupold's full-sized avatar

Michael Scherbakow ryupold

View GitHub Profile
@ryupold
ryupold / FileDrop.java
Created September 30, 2014 16:36
Dragging and Droping Files onto a Component
package oracle.forms.gp;
import java.awt.datatransfer.DataFlavor;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.io.Reader;
/**
@ryupold
ryupold / Config.java
Last active August 29, 2015 14:07
static Config class for writing simple xml key value pairs
public final class Config{
private Config(){}
private final static String configPath;
private final static File configFile;
private static Document document;
private static Element doc;
static
{
configPath = System.getProperty("user.home") + File.pathSeparator +".PROGRAMNAME"+File.pathSeparator+"config.xml";
@ryupold
ryupold / WaitDialog.java
Created October 18, 2014 16:38
Asyncronous processing while showing a [modal] progress window
/**
*
* @author Ryupold
*/
public class WaitDialog extends javax.swing.JDialog {
private static interface ProcessingListener {
void onProcess(double percent, String processingStep);
}
@ryupold
ryupold / GetImageFromURI.cs
Last active June 3, 2020 09:31
Get file path from Content-URI in Android (Xamarin)
private string GetImageFromURI(Uri contentURI)
{
return MediaStore.Images.Media.GetBitmap(ContentResolver, contentURI);
}
@ryupold
ryupold / BitmapRegionDecoder.java
Created August 10, 2015 13:49
BitmapRegionDecoder
BitmapRegionDecoder decoder = BitmapRegionDecoder.newInstance(myStream, false);
Bitmap region = decoder.decodeRegion(new Rect(10, 10, 50, 50), null);
@ryupold
ryupold / ThumbnailBitmap.cs
Created August 10, 2015 14:20
create thumbnail of large BitmapImage (Android/Xamarin)
public Bitmap GetThumbnail(Uri uri, int thumbnailSize)
{
var input = this.ContentResolver.OpenInputStream(uri);
BitmapFactory.Options onlyBoundsOptions = new BitmapFactory.Options();
onlyBoundsOptions.InJustDecodeBounds = true;
onlyBoundsOptions.InDither = true; //optional
onlyBoundsOptions.InPreferredConfig = Bitmap.Config.Argb8888; //optional
BitmapFactory.DecodeStream(input, null, onlyBoundsOptions);
input.Close();
@ryupold
ryupold / errsol.json
Last active September 21, 2015 08:21
Errors & Solutions
{
"errors":["Failed to initialize the PowerShell host. If your PowerShell execution policy setting is set to AllSigned, open the Package Manager Console to initialize the host first."],
"solutions":[
{
"sources":["http://stackoverflow.com/questions/23353951/cant-install-nuget-package-because-of-failed-to-initialize-the-powershell-host"],
"description":"set execution policy to unrestricted",
"action":"PowerShell (as Admin): start-job { Set-ExecutionPolicy Unrestricted } -RunAs32 | wait-job | Receive-Job"
},
{
"sources":["http://stackoverflow.com/questions/23353951/cant-install-nuget-package-because-of-failed-to-initialize-the-powershell-host"],
@ryupold
ryupold / CheckHit.cs
Last active March 21, 2016 11:54
Unity Scripts
public class CheckHit : MonoBehaviour
protected Node CheckHit(Vector2 screenPos, int layer=-1)
{
RaycastHit hitInfo;
var hit = layer == -1 ?
Physics.Raycast(Camera.main.ScreenPointToRay(screenPos), out hitInfo, 1000f):
Physics.Raycast(Camera.main.ScreenPointToRay(screenPos), out hitInfo, 1000f, layer);
lastRay = Camera.main.ScreenPointToRay(screenPos);
if (hit)
@ryupold
ryupold / test-loop.ps1
Last active December 1, 2015 10:35
loop test runs with nunit-console 3.0
$successTimeout = 5
$failedTimeout = 60
$command = "nunit3-console.exe --noresult "+$args[0]
if($args[0])
{
write-host "testing",$args[0]
write-host "NOTE: nunit3-console.exe needs to be in PATH"
echo ""
echo ""
@ryupold
ryupold / PropertyUtils.cs
Last active March 21, 2016 11:56
simplifies creation of DependencyProperties (XAML)
public static class PropertyUtils
{
public static DependencyProperty CreateProperty<TProperty, TOwner> (string propertyName, Action<TOwner, TProperty, TProperty> onChange, TProperty defaultValue=default(TProperty)) where TOwner : class
{
return DependencyProperty.Register(propertyName, typeof (TProperty), typeof (TOwner),
new PropertyMetadata(defaultValue, (o, args) =>
{
onChange(o as TOwner, (TProperty)args.OldValue, (TProperty)args.NewValue);
}));
}