Skip to content

Instantly share code, notes, and snippets.

View Karloid's full-sized avatar
🎯
Focusing

Karloid

🎯
Focusing
View GitHub Profile
@Karloid
Karloid / TestMidi.java
Created March 15, 2013 20:41
TestMidi
import javax.sound.midi.MidiChannel;
import javax.sound.midi.MidiSystem;
import javax.sound.midi.Synthesizer;
public class TestMidi {
public static void main(String[] args) {
try {
Synthesizer synthesizer = MidiSystem.getSynthesizer();
synthesizer.open();
@Karloid
Karloid / gist:5283383
Created April 1, 2013 05:32
segmentsIntersect
public boolean segmentsIntersect(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) {
double d = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
if (d == 0) return false;
double xi = Math.floor(((x3 - x4) * (x1 * y2 - y1 * x2) - (x1 - x2) * (x3 * y4 - y3 * x4)) / d);
double yi = Math.floor(((y3 - y4) * (x1 * y2 - y1 * x2) - (y1 - y2) * (x3 * y4 - y3 * x4)) / d);
if (xi < Math.min(x1, x2) - 15 || xi > Math.max(x1, x2) + 15) return false;
if (xi < Math.min(x3, x4) - 15 || xi > Math.max(x3, x4) + 15) return false;
if (yi < Math.min(y1, y2) - 15 || yi > Math.max(y1, y2) + 15) return false;
if (yi < Math.min(y3, y4) - 15 || yi > Math.max(y3, y4) + 15) return false;
/*Косяки с вычислениями в double*/
@Karloid
Karloid / gist:5454809
Created April 24, 2013 19:22
test sql jdbc connection
private static void testPostgreSql()throws SQLException {
try {
Class.forName("org.postgresql.Driver");
} catch (ClassNotFoundException e) {
System.out.println("Where is your JDBC Driver?");
e.printStackTrace();
return;
}
String url = "jdbc:postgresql://127.0.0.1:5432/postgres";
@Karloid
Karloid / gist:5781186
Created June 14, 2013 11:35
image to byte array
File urlImage = new File("path to file");
BufferedImage img = ImageIO.read(urlImage);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(img, "jpg", baos);
baos.flush();
byte[] bytes = baos.toByteArray();
baos.close();
package org.kilonet;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
/*
* The author disclaims copyright to this source code. In place of
* a legal notice, here is a blessing:
*
* May you do good and not evil.
* May you find forgiveness for yourself and forgive others.
* May you share freely, never taking more than you give.
*
*/
package org.hibernate.dialect;
package org.kilonet;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
@Karloid
Karloid / gist:33c3d0b828667d5429c47ac247f2cc71
Created June 13, 2021 09:51
swift : The compiler is unable to type-check this expression in reasonable time
//
// main.swift
// SwiftShowcase
//
import Foundation
struct Struct1 {
let constant : CGFloat = 10
}
package demosql
import java.sql.*
class ServerDatabase {
val conn: Connection
init {
@Karloid
Karloid / ImageGenerator.java
Created February 25, 2023 13:27
ImageGenerator java example
package catbot;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
public class ImageGenerator {
public static void main(String[] args) {