Skip to content

Instantly share code, notes, and snippets.

View jonnyli1125's full-sized avatar

Jonny Li jonnyli1125

View GitHub Profile
@jonnyli1125
jonnyli1125 / PluginFormat.cs
Created August 27, 2012 08:50
MCDawn Plugin Format
using System;
namespace MCDawn
{
public class PluginName : Plugin
{
public override string Name { get { return "pluginname"; } } // name, all in lowercase
public override string PluginVersion { get { return "1.0"; } } // version
public override string MCDawnVersion { get { return "1.0.1.2"; } } // compatible mcdawn version
public override void LoadPlugin()
@jonnyli1125
jonnyli1125 / gist:4188092
Created December 2, 2012 10:29
Integer Square Root
public static int IntSqrt(int num) // Faster than Math.Sqrt, because that uses doubles.
{
if (num < 0) throw new Exception("Cannot get square root of negative number.");
if (0 == num) return 0; // Avoid zero divide
int n = (num / 2) + 1; // Initial estimate, never low
int n1 = (n + (num / n)) / 2;
while (n1 < n)
{
n = n1;
n1 = (n + (num / n)) / 2;
@jonnyli1125
jonnyli1125 / MerryHaxmas.txt
Created December 19, 2012 17:34
Merry Haxmas!
,
_/^\_
< hax >
/.-.\
* MERRY * `/&\`
,@.*;@,
/_o.I %_\
(`'--:o(_@;
/`;--.,__ `')
;@`o % O,*`'`&\
@jonnyli1125
jonnyli1125 / OnGround.cs
Created December 25, 2012 05:10
MCDawn - Player.OnGround
public static bool OnGround(Player p) {
if (!Block.Walkthrough(p.level.GetTile((ushort)(p.pos[0] / 32), (ushort)((p.pos[1] / 32) - 2), (ushort)(p.pos[2] / 32)))) return true;
return false;
}
@jonnyli1125
jonnyli1125 / convert.txt
Created January 27, 2013 19:26
How to convert Minecraft player position and look packets to more readable values.
x = (player.x / 32)
y = (player.y / 32)
z = (player.z / 32)
pitch = round((double)(player.pitch * (360 / 256)))
yaw = round((double)((-(sbyte)(player.yaw)) * (360 / 256)))
@jonnyli1125
jonnyli1125 / BinarySearch.cs
Last active December 12, 2015 01:18
A little test of using a binary search algorithm to find indexes of values in a sorted list. Also just a little comparison between binary and linear/sequential searching.
using System;
using System.Collections.Generic;
namespace BinarySearch
{
class Program
{
static void Main(string[] args)
{
List<int> list = new List<int>() { 5, 8, 900, 1, 22, 52, 567, 666, 123, 256, 765, 0, 500 }; // example list
@jonnyli1125
jonnyli1125 / jonnyeclipse.epf
Last active December 14, 2015 03:48
My Eclipse color theme.
file_export_version=3.0
/instance/org.codehaus.groovy.eclipse.ui/groovy.editor.groovyDoc.keyword.enabled=true
/instance/org.codehaus.groovy.eclipse.ui/groovy.editor.groovyDoc.link.enabled=true
/instance/org.codehaus.groovy.eclipse.ui/groovy.editor.groovyDoc.tag.enabled=true
/instance/org.eclipse.ui.editors/AbstractTextEditor.Color.SelectionForeground.SystemDefault=false
/instance/org.eclipse.ui.editors/AbstractTextEditor.Color.SelectionBackground.SystemDefault=false
/instance/org.eclipse.ui.editors/AbstractTextEditor.Color.Background.SystemDefault=false
/instance/org.eclipse.ui.editors/AbstractTextEditor.Color.Foreground.SystemDefault=false
/instance/org.epic.perleditor/AbstractTextEditor.Color.Background.SystemDefault=false
/instance/org.epic.perleditor/AbstractTextEditor.Color.Foreground.SystemDefault=false
@jonnyli1125
jonnyli1125 / custom.css
Last active June 19, 2020 04:50
japanese font solution for discord with betterdiscord custom css
div>*:not(code) {
/* using the default discord theme's fonts */
font-family:
Whitney,
'Helvetica Neue',
Helvetica,
Arial,
'Meiryo', /* you can change this to whatever japanese font you prefer */
sans-serif !important;
}
@jonnyli1125
jonnyli1125 / weighted_sparse_categorical_crossentropy.py
Last active June 11, 2024 08:33
SparseCategoricalCrossentropy with class weights for Keras/Tensorflow 2
"""
Since Model.fit doesn't support class_weight when using multiple outputs,
this custom loss subclass may be useful.
Relevant issues:
https://github.com/keras-team/keras/issues/11735
https://github.com/tensorflow/tensorflow/issues/40457
https://github.com/tensorflow/tensorflow/issues/41448
"""
@jonnyli1125
jonnyli1125 / stockfish_selfplay.py
Created June 21, 2021 04:23
Stockfish self-play game generation script
import argparse
import chess
import chess.engine
import chess.pgn
def main(stockfish_path, output_path):
engine = chess.engine.SimpleEngine.popen_uci(stockfish_path)