Skip to content

Instantly share code, notes, and snippets.

View paveltimofeev's full-sized avatar

Pavel Timofeev paveltimofeev

View GitHub Profile
@paveltimofeev
paveltimofeev / GenericFactoryMethodPattern.cs
Created July 5, 2011 06:00
Generic FactoryMethod Pattern
/* Одним из недостатков шаблона FactoryMethod является необходимость создания отдельного Creator'а для каждого Product'а.
Данный подход позволяет использовать GenericCreator для создания любого Product'а.*/
///
/// This is base class (super class) for FactoryMethod
///
internal abstract class FactoryMethodCreatorBase
{
public abstract FactoryMethodProductBase FactoryMethod();
@paveltimofeev
paveltimofeev / SqlModelAddon.cs
Created July 5, 2011 06:51
Addon for SqlModel framework
/// <summary>
/// Преобразует значение ячейки DataTable'а в указанный тип или возвращает значение по умолчанию, если в ящейке нет данных (DBNull)
/// </summary>
/// <typeparam name="T">Целевой тип, должен реализовывать IConvertible</typeparam>
/// <param name="value">Значение ячейки</param>
/// <param name="defaultValue">Значение по умолчанию</param>
public static T GetValue<T>(object value, T defaultValue)
where T : IConvertible
{
if (Convert.IsDBNull(value))
@paveltimofeev
paveltimofeev / SSH-SCP Sync
Created November 28, 2014 16:32
SSH/SCP Sync
#! /bin/bash
# SSH/SCP Sync
# use in this way:
# bash sync.sh '/c/Git/Project/forder-for-sync/*' '10.0.0.10' '/home/username/forder-for-sync/' '/c/sshKeys/key.pem'
args=("$@")
SRCFOLDER=${args[0]} # '/c/Git/Project/forder-for-sync/*'
TRGHOST=${args[1]} # '10.0.0.10'
@paveltimofeev
paveltimofeev / colored-output-for-node.js
Last active August 29, 2015 14:14
Colored Output for NodeJS
// 0m - WHITE ON BLACK
// 32m GREEN
console.log( '\x1b[0m\x1b[32m%s\x1b[0m %s\x1b[0m', message1, message2 );
// 31m - RED
console.log( '\x1b[0m\x1b[31mRed Message\x1b[0m %s\x1b[0m', message );
@paveltimofeev
paveltimofeev / VirtualBoxCommands
Last active March 18, 2016 20:26
VirtualBox command
REM will start the specified virtual machine in the background.
REM To shut it down, request the shut down from the guest.
C:\Program Files\Oracle\VirtualBox\VBoxManage startvm $VM --type headless
REM enable symlinks on shared folders
C:\Program Files\Oracle\VirtualBox\VBoxManage setextradata YOUR_VM_NAME VBoxInternal2/SharedFoldersEnableSymlinksCreate/YOUR_SHAR_EFOLDER_NAME 1
# Install Video at Ubuntu (Fix SCREEN Resolution)
sudo apt-get install virtualbox-guest-utils virtualbox-guest-x11 virtualbox-guest-dkms
@paveltimofeev
paveltimofeev / Elasticsearch queries.js
Last active August 29, 2015 14:23
Elasticsearch queries
--------------------------------------------------
How to return objects wich contains empty array?
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#query-string-syntax
[GET] /index/type/_search?q=-_exists_:array_field
[RESPONSE]:
"hits" :
{
...
"hits" :
[
@paveltimofeev
paveltimofeev / bind.js
Last active August 29, 2015 14:24
JavaScript hooks, patterns, tricks
/// Bind
function done(){
console.log('> Done');
console.log( arguments );
}
function request( context, url, _done) { _done( context, url, _done ); }
@paveltimofeev
paveltimofeev / fitnesse-udl.xml
Created August 13, 2015 09:35
Fitnesse user defined language schema for Notepad++
<NotepadPlus>
<UserLang name="Fitnesse" ext=".txt" udlVersion="2.1">
<Settings>
<Global caseIgnored="no" allowFoldOfComments="yes" foldCompact="no" forcePureLC="0" decimalSeparator="0" />
<Prefix Keywords1="no" Keywords2="yes" Keywords3="yes" Keywords4="no" Keywords5="yes" Keywords6="no" Keywords7="no" Keywords8="no" />
</Settings>
<KeywordLists>
<Keywords name="Comments">00# 01 02 03!| 04|</Keywords>
<Keywords name="Numbers, prefix1"></Keywords>
<Keywords name="Numbers, prefix2"></Keywords>
@paveltimofeev
paveltimofeev / LockPC.ps1
Last active September 10, 2015 08:56
Locking PC after some minutes (powershell script / WIN)
cls
function Wait-For
{
param( $minutes, $callback )
$untill = (Get-Date).AddMinutes($minutes)
Wait-Untill $untill.Hour $untill.Minute $callback
}
@paveltimofeev
paveltimofeev / Show-BalloonTip.ps1
Created September 10, 2015 10:37
Show-BalloonTip
function Show-BalloonTip
{
[CmdletBinding(SupportsShouldProcess = $true)]
param
(
[Parameter(Mandatory=$true)] $Text,
[Parameter(Mandatory=$true)] $Title,
[ValidateSet('None', 'Info', 'Warning', 'Error')] $Icon = 'Info',
$Timeout = 10000
)