Skip to content

Instantly share code, notes, and snippets.

View 13xforever's full-sized avatar
💮
わたしは あの路で死んだ花

Ilya 13xforever

💮
わたしは あの路で死んだ花
View GitHub Profile
@13xforever
13xforever / CastingHelper.cs
Created May 30, 2012 12:06
Casting array of bytes to struct and vice versa in C#
public static class CastingHelper
{
public static T CastToStruct<T>(this byte[] data) where T : struct
{
var pData = GCHandle.Alloc(data, GCHandleType.Pinned);
var result = (T)Marshal.PtrToStructure(pData.AddrOfPinnedObject(), typeof(T));
pData.Free();
return result;
}
@13xforever
13xforever / Statistics.cs
Last active March 25, 2021 11:30
Some statistics functions
using System;
using System.Collections.Generic;
using System.Numerics;
namespace Math.Statistics
{
public static class Statistics
{
public static long Mean(this IEnumerable<long> data)
{
@13xforever
13xforever / StringLiteralDecoder.cs
Created March 27, 2011 11:33
Utility class to decode strings with literals in it
/*
This class should decode everything that is described in Chapter 2.4.4.4 Character literals of C# Language Specification.
See http://msdn.microsoft.com/en-us/library/aa691087.aspx for details.
I actually have test cases in the project in case you wondered, but feel free to test it for yourself.
It's free to use without limitations, but you must not expect any warranty or support for this code either.
*/
@13xforever
13xforever / x.js
Last active August 29, 2015 18:25
QR-Code generator ubiquity commnd
CmdUtils.CreateCommand({
names: ['qr code', 'encode'],
icon: "http://img205.imageshack.us/img205/231/qrcodezh1.gif",
description: "Generates QR Code image based on selected url",
argument: noun_type_url,
preview: function(pBlock, {object}) {
pBlock.innerHTML = '<img src="' + 'http://qrcode.kaywa.com/img.php?s=6&d=' + escape(object.text) + '" />';
},
execute: function(args) {
Utils.openUrlInBrowser('http://qrcode.kaywa.com/img.php?s=8&d=' + escape(args.object.text));