Skip to content

Instantly share code, notes, and snippets.

View dimzon's full-sized avatar

Dmitry dimzon

  • Wintegra
  • Russian Federation
View GitHub Profile
@dimzon
dimzon / RowClassTypeBuilder.cs
Created June 18, 2017 11:06
Dapper dynamic object generation
namespace ePrinting
{
using System;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using PropertyAttributes = System.Reflection.PropertyAttributes;
// based on https://stackoverflow.com/questions/3862226/how-to-dynamically-create-a-class-in-c
@dimzon
dimzon / base32.sql
Created June 13, 2017 01:03 — forked from rmalayter/base32.sql
Base32 encoding and decoding functions in Microsoft T-SQL
IF EXISTS (
SELECT *
FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[base32enc]')
AND type IN (
N'FN'
,N'IF'
,N'TF'
,N'FS'
,N'FT'
@dimzon
dimzon / CsvUtils.cs
Last active April 23, 2017 05:48
Простая работа с CSV
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using Microsoft.VisualBasic.FileIO;
namespace IKompass.PreparePDF.IO
{
public static class CsvUtils
{
@dimzon
dimzon / opera-vpn.md
Created August 28, 2016 19:40 — forked from spaze/opera-vpn.md
Opera VPN behind the curtains is just a proxy, here's how it works

When setting up (that's immediately when user enables it in settings) Opera VPN sends few API requests to https://api.surfeasy.com to obtain credentials and proxy IPs, see below, also see The Oprah Proxy.

The browser then talks to a proxy de0.opera-proxy.net (when VPN location is set to Germany), it's IP address can only be resolved from within Opera when VPN is on, it's 185.108.219.42 (or similar, see below). It's an HTTP/S proxy which requires auth.

When loading a page with Opera VPN enabled, the browser sends a lot of requests to de0.opera-proxy.net with Proxy-Authorization request header.

The Proxy-Authorization header decoded: CC68FE24C34B5B2414FB1DC116342EADA7D5C46B:9B9BE3FAE674A33D1820315F4CC94372926C8210B6AEC0B662EC7CAD611D86A3 (that's sha1(device_id):device_password, where device_id and device_password come from the POST /v2/register_device API call, please note that this decoded header is from another Opera installation and thus contains

package com.github.dimzon.gson.gbson;
import com.google.gson.*;
import com.google.gson.internal.JsonReaderInternalAccess;
import com.google.gson.internal.bind.TypeAdapters;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
import com.google.gson.stream.JsonWriter;
import com.mongodb.BasicDBList;
import com.mongodb.BasicDBObject;
@dimzon
dimzon / mongo-array-tools.php
Created September 10, 2015 20:29
MongoDB array tools (assoc <-> object consversions)
<?php
class mongo_tools {
public static function assoc2obj($a){
self::assoc2objects_inplace($a);
return $a;
}
public static function obj2assoc($o){
self::objects2assoc_inplace($o);
return $o;
@dimzon
dimzon / example.php
Last active July 30, 2016 08:30
Persisting PHP sessions into mongodb (allows NLB without affinity)
<?php
// all default values
MongoSessionPersistence::create()
->connect()
->register();
// connect to concrete server/db
MongoSessionPersistence::create()
->connect('mongodb://mongo_server:27017', 'databaseName')
->useLifeTime(60*60) // lifetime=1 hour
@dimzon
dimzon / MurMurHash3.cs
Last active August 29, 2015 14:28 — forked from automatonic/MurMurHash3.cs
MurMurHash3 .Net (C#) implementation
/*
This code is public domain.
The MurmurHash3 algorithm was created by Austin Appleby and put into the public domain. See http://code.google.com/p/smhasher/
This C# variant was authored by
Elliott B. Edwards and was placed into the public domain as a gist
Status...Working on verification (Test Suite)
Set up to run as a LinqPad (linqpad.net) script (thus the ".Dump()" call)
*/
@dimzon
dimzon / show-ip-address.sh
Last active August 29, 2015 14:27 — forked from P7h/show-ip-address.sh
For showing IP Address before the login prompt on Ubuntu env. Copy the following script to /etc/network/if-up.d/ and /etc/network/if-post-down.d/ folders. And don’t forget to mark them as executables.
# This shell script displays hostname and IP Address of the Ubuntu machine before the login prompt.
# Add this file to '/etc/network/if-up.d/' and '/etc/network/if-post-down.d/' folders and mark them as executables.
# Display Ubuntu default information [the current version of Ubuntu].
cat /etc/issue.net > /etc/issue
# Display the hostname.
hostname >> /etc/issue
# Display the IP Address of eth0.
@dimzon
dimzon / links.txt
Last active August 29, 2015 14:19 — forked from MohamedAlaa/tmux-cheatsheet.markdown
screen && tmux