Skip to content

Instantly share code, notes, and snippets.

View uugan's full-sized avatar

Uugan uugan

  • Ulaanbaatar, Mongolia
View GitHub Profile
@uugan
uugan / windows1251_to_utf8.java
Created March 22, 2019 05:15
Encoding windows-1251|cp1251 to utf-8
public static String windows1251_to_utf8(String str_1251) throws Exception{
String str_utf8 = "";
for(int i=0;i<str_1251.length();i++){
int c = Character.codePointAt(str_1251,i);
switch (c){
case 184: c=1105;break; //eo
case 168: c=1025;break; // capital EO
case 175: c=1198; break; //capital UE
case 191: c=1199; break; //ue
@uugan
uugan / ControlExtentions.cs
Created November 15, 2017 05:32
C# control extention for invoke methods
public static class ControlExtentions
{
public static void InvokeIfNeeded(this Control control, Action doit)
{
if (control.InvokeRequired)
control.Invoke(doit);
else
doit();
}
@uugan
uugan / vb_eng_to_mon.vb
Last active March 15, 2017 02:17
VBA Outlook 2013 latin to cyrillic transliteration (mongolian)
'http://www.utf8-chartable.de/unicode-utf8-table.pl?start=1024&utf8=-&unicodeinhtml=dec
Public Sub RunEngToMon()
Dim msg As Outlook.MailItem
Dim insp As Outlook.Inspector
Dim strTemp As String
If Application.ActiveInspector Is Nothing Then
If Application.ActiveExplorer.Selection.Count = 1 Then
If Application.ActiveExplorer.Selection.Item(1).Class = olMail Then
Set msg = Application.ActiveExplorer.Selection.Item(1)
@uugan
uugan / get_youtube_playlist
Last active January 27, 2016 19:48
Youtube playlist video to mp3 downloader bash script sudo apt-get install youtube-dl ffmpeg or libavcodec-extra-53
#!/bin/bash
usage='usage:
./get_youtube_playlist <playlist_id> <target_folder> <num_songs>
target_folder: (default: songs will be downloaded in current folder)
num_songs: number of songs to get (default: 50)
examples:
./get_youtube_playlist RD02HIkZaLeuF9k
./get_youtube_playlist RD02HIkZaLeuF9k "my jazz" 10
@uugan
uugan / MagicSquare.java
Created June 13, 2013 13:33
Shows Magic square by odd, doubly even & singly even numbers
/*************************************************************************
*
* This code generates a magic square for odd or even number.
* Based on methods :
* http://www.1728.org/magicsq1.htm - odd
* http://www.1728.org/magicsq2.htm - doublyEven
* http://www.1728.org/magicsq3.htm - singlyEven
* code by : uugan
* date : 01.06.2013
* Compilation: javac MagicSquare.java
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
namespace GVF {
class gvf_field {
const double pi = 3.14159;
/* Histogram hyperbolic equalization */
float hyperbolic_histogram(unsigned char* inbuf, unsigned char* outbuf, int height,int width){
double g_min=255;
double g_max=0;
double* histogram = new double[256];
double* cdf = new double[256]; /* generates Pf(f) */
double* out = new double[height*width]; /* output array of doubles */
int start = GetTickCount();
for(int i=0;i<256;i++) {
/* Histogram exponential equalization when alpha = 0.011 */
float exponential_histogram(unsigned char* inbuf, unsigned char* outbuf, int height, int width){
double g_min=255;
double g_max=0;
double* histogram = new double[256];
/* histogram array */
double* cdf = new double[256]; /*Pf(f) values [cumulative distribution function]*/
double* out = new double[height*width];
int start = GetTickCount();
for(int i=0;i<256;i++)
/* Histogram 2/3 degrees */
float hyperbolic_cube_root(unsigned char* inbuf, unsigned char* outbuf, int height, int width){
int g_min=255;
int g_max=0;
double* histogram = new double[256]; /* histogram array 0..255*/
double* cdf = new double[256]; /*Pf(f) cumulative distrib function */
double* out = new double[height*width];
int start = GetTickCount();
for(int i=0;i<256;i++) {
/* Smoothing image by K nearest neighbors */
float SmoothbyKNN(unsigned char *inbuf, unsigned char* outbuf, int height, int width){
int start = GetTickCount();
int _k = 6; // _k<n*n
int _n = 3; // 3x3
int p = 1; // 3/2
int raz[9];
int tmp=0, cnt=0, sum=0;
double* out = new double[height*width];
for(int i=p;i<height-p;i++)