Skip to content

Instantly share code, notes, and snippets.

View sebgod's full-sized avatar

Sebastian Godelet sebgod

View GitHub Profile
@sebgod
sebgod / Hello.java
Last active August 29, 2015 14:03
Testing UTF-8 as a default output for Windows
class Hello {
public static boolean ensureEncodingToUTF8() {
String osEncoding = System.getProperty("file.encoding");
if (!osEncoding.equals("UTF-8") || !osEncoding.equals("UTF8")) {
java.lang.System.setProperty("file.encoding", "UTF-8");
try {
System.setOut(new java.io.PrintStream(System.out, true, "UTF-8"));
} catch (Exception inner) {
return false;
}
:- module fmt_bug.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
:- implementation.
:- import_module float.
:- import_module list.
@sebgod
sebgod / FirstCharUtf32.cs
Last active August 29, 2015 14:03
A astral character safe first char method for C#
static class FirstCharUtf32 {
public static bool FirstChar(string Str, out int First) {
bool SUCCESS_INDICATOR;
int len = Str.Length;
if (len > 0) {
First = Str[0];
if (char.IsSurrogate((char)First)) {
if (SUCCESS_INDICATOR = char.IsSurrogatePair(Str, 0)) {
First = char.ConvertToUtf32((char)First, Str[1]);
}
@sebgod
sebgod / string_encoding.m
Last active August 29, 2015 14:02
Adding Unicode transformation functions to the string module
%----------------------------------------------------------------------------%
% vim: ft=mercury ff=unix ts=4 sw=4 tw=78 et
%----------------------------------------------------------------------------%
% File: string_encoding.m
% Copyright © 2014 Sebastian Godelet
% Main author: Sebastian Godelet <sebastian.godelet+github@gmail.com>
% Created on: Sun Jun 22 11:13:20 CEST 2014
% Stability: low
%----------------------------------------------------------------------------%
% A little effort to implement UTF-16 support for strings.
@sebgod
sebgod / test_win_unicode.cmd
Last active August 6, 2016 02:40
Testing pure Win32 console output vs io.print/write
@setlocal enabledelayedexpansion
@chcp 850 2>nul 1>nul
@set JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF8
@if "%~1" EQU "" @(
set grades=mercury --libgrades-exclude stseg --libgrades-exclude trseg
set grades=!grades! --libgrades-exclude pregen --libgrades-exclude memprof
set grades=!grades! --output-libgrades
) else (
set grades=echo %*
@sebgod
sebgod / c_files_to_html.sh
Created May 8, 2014 21:23
Convert c files to HTML using Vim
for f in *.[ch]; do gvim -f +"syn on" +"run! syntax/2html.vim" +"wq" +"q" $f; done
@sebgod
sebgod / all_unicode_digits.cs
Last active August 29, 2015 14:01
Lists all Unicode digits in a Console application, including astral characters
public class AlllUnicodeDigits {
public static void Main()
{
var unicodeEncoding = new UnicodeEncoding(!BitConverter.IsLittleEndian, false);
Console.InputEncoding = unicodeEncoding;
Console.OutputEncoding = unicodeEncoding;
var sb = new StringBuilder();
for (var codePoint = 0; codePoint < 0x10ffff; codePoint++)
{
@sebgod
sebgod / mmi
Last active August 29, 2015 14:01
Mercury shell script
#!/bin/sh
if [ $# -eq 0 ]; then
exit 1 # the first argument *MUST* be the executed script
fi
if [ -x $1 ]; then
SHELL_SCRIPT=$(basename $0)
SCRIPT=$1
mv -f $SCRIPT ${SCRIPT}.tmp
shift
/// <reference path="bluebird.d.ts" />
import Promise = require("bluebird");
Promise.cast(8).then(x => console.log(x.toExponential()));
function delayer(time: number) {
var d = Promise.defer();
setTimeout(_ => d.resolve, time);
function addTableRow(jQtable){
jQtable.each(function(){
var $table = $(this);
// Number of td's in the last table row
var n = $('tr:last td', this).length;
var tds = '<tr>';
for(var i = 0; i < n; i++){
tds += '<td>&nbsp;</td>';
}
tds += '</tr>';