Skip to content

Instantly share code, notes, and snippets.

View Enelar's full-sized avatar
💭
https://www.linkedin.com/in/offenso

Kirill Berezin Enelar

💭
https://www.linkedin.com/in/offenso
View GitHub Profile
@Enelar
Enelar / dynamic_construction_choose.cpp
Created March 20, 2014 10:30
With this gist you could get array of object overloaded methods(lambda+circuit) by its names. For simple example i support only constructors, but i hope you realize `what you should change` to get every function you want.
#include <functional>
#include <iostream>
using namespace std;
struct objT
{
};
struct a : objT
@Enelar
Enelar / tuple_type_pos.cpp
Created March 30, 2014 21:55
Determine type first position in tuple. Ugly, but working
template<typename Type, typename Tuple, int level = -30>
struct get_type_pos
{
typedef typename tuple_element<level, Tuple>::type selected_type;
static constexpr bool same = is_same<selected_type, Type>::value;
static int Get()
{
return GetA<int>();
}
@Enelar
Enelar / filler.cpp
Created April 22, 2014 17:21
Filler object with some size
#pragma once
#include <type_traits>
template<int wished_size>
struct filler
{
static const int word_size = sizeof(int);
static const int actual_size_in_words = (wished_size + word_size - 1) / word_size;
@Enelar
Enelar / pg_add_column.php
Created May 13, 2014 13:24
Posgtresql add column after or before.
// Warning! You lose all constraight's
// All depended views NOT updating
function AddColumnPos( $table_name, $pos, $name, $data_type )
{
db::Query("BEGIN");
db::Query("LOCK TABLE {$table_name} IN ACCESS EXCLUSIVE MODE");
db::Query("SET CONSTRAINTS ALL DEFERRED");
$cols = db::Query("SELECT column_name as name, data_type as type FROM information_schema.columns WHERE table_name='{$table_name}'");
@Enelar
Enelar / pgarrays.php
Created May 23, 2014 10:03
php to postgres(and back) arrays convert
<?php
// http://www.youlikeprogramming.com/2013/01/interfacing-postgresqls-hstore-with-php/
function pgArrayToPhp($text)
{
if(is_null($text))
return [];
if(!is_string($text) && $text == '{}')
return [];
@Enelar
Enelar / hook.js
Last active August 29, 2015 14:03
Javascript load every function call
function HookObject(hook, depth)
{
var k, fn;
if (typeof depth === 'undefined')
depth = -1;
// https://gist.github.com/Enelar/34f9ef9ee412cb88beb4
var _CloneObject = CloneObject;
function Helper(name, fn)
@Enelar
Enelar / clone.js
Created July 11, 2014 05:33
Emulate clone constructor in js
function CloneObject(obj)
{
if (obj === null)
return obj;
if (typeof obj !== "object")
return obj;
var copy = obj.constructor();
for (var attr in obj)
if (obj.hasOwnProperty(attr))
@Enelar
Enelar / constexpr_string.cpp
Created August 12, 2014 19:01
Simple constexpression string container
// Introduced by Scott Schurr in "C++ Now! 2012"
class constexpr_string
{
protected:
const char* const p;
const std::size_t s;
public:
template<std::size_t N>
constexpr constexpr_string(const char(&a)[N])
: p(a), s(N-1)
@Enelar
Enelar / selection_sort.asm
Created January 24, 2015 13:09
One friend asked help with home work. Its crappy snippet perform selection sort.
.686
.model flat
.stack
data segment "data"
data ends
.CODE
@Enelar
Enelar / sublime_text_3.sh
Last active August 29, 2015 14:21
Any yum based linux Sublime Text 3 install (into /opt with current user shortcut)
#!/bin/bash
# http://stackoverflow.com/questions/5947742/how-to-change-the-output-color-of-echo-in-linux
RED='\033[0;31m'
NC='\033[0m' # No Color
printf "${RED}Check&install required utility${NC}\n"
rpmqa=`rpm -qa`
echo $rpmqa | grep -qw lynx || sudo yum install lynx
echo $rpmqa | grep -qw wget || sudo yum install wget