Skip to content

Instantly share code, notes, and snippets.

import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.Charset;
/**
* Create codepage files for supported encodings.
* @author aNNiMON
*/
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import javax.imageio.ImageIO;
/**
import javax.swing.JOptionPane;
/**
* @author aNNiMON
*/
public class SpiralAlgorithm {
private static enum Directions {
UP {
@Override
private int julery_isqrt(int val) {
int temp, g = 0, b = 0x8000, bshft = 15;
do {
if (val >= (temp = (((g << 1) + b) << bshft--))) {
g += b;
val -= temp;
}
} while ((b >>= 1) > 0);
return g;
}
@aNNiMON
aNNiMON / Java8Examples.java
Last active August 29, 2015 13:56
Java 8 examples
package com.app1;
import java.time.Duration;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.Month;
import java.time.Period;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
@aNNiMON
aNNiMON / HttpServer.java
Created March 23, 2014 10:11
HttpServer
package socket;
import java.net.ServerSocket;
import java.net.Socket;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
/**
@aNNiMON
aNNiMON / PrintJar.java
Created April 5, 2014 11:17
Java 8 print text based resource file inside a jar file. (eg: META-INF/MANIFEST.MF)
package ztools;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Optional;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
/**
public static ushort GetMonitorBrightness() {
using (var mclass = new ManagementClass("WmiMonitorBrightness")) {
mclass.Scope = new ManagementScope(@"\\.\root\wmi");
using (var instances = mclass.GetInstances()) {
foreach (ManagementObject instance in instances) {
return (byte) instance.GetPropertyValue("CurrentBrightness");
}
}
}
return 0;
@aNNiMON
aNNiMON / AlgorithmMarkov.java
Last active August 29, 2015 13:58
Алгоритм Маркова
package algorithmmarkov;
import java.util.ArrayList;
public class AlgorithmMarkov {
public static void main(String[] args) {
Rules rules4to2 = Rules.create()
.add("~0", "00~")
.add("~1", "01~")
@aNNiMON
aNNiMON / Activity.md
Last active August 29, 2015 13:59
Android Best Practices

Activity

New Instance

public class ExampleActivity extends Activity {

    public static final String EXTRA_PRODUCT_ID = "product_id";
    public static final String EXTRA_PRODUCT_TITLE = "product_title";

    public static Intent newIntent(Context context, long productId, String productTitle) {
 final Intent intent = new Intent(context, ExampleActivity.class);