Skip to content

Instantly share code, notes, and snippets.

View Lazin's full-sized avatar

Eugene Lazin Lazin

  • Redpanda Data
  • The Hague, Netherlands
  • X @Lazin
View GitHub Profile
public class SafeByte
{
ReaderWriterLockSlim locker = new ReaderWriterLockSlim();
byte val;
public byte Value {
get {
using (ReadLock read = new ReadLock(locker)) {
return val;
class ConcurrentCounter {
unsigned int* counters_;
int length_;
public:
ConcurrentCounter() {
length_ = boost::thread::hardware_concurrency() * 0x100;
counters_ = new unsigned int[length_];
std::fill(counters_, counters_ + length_, 0);
}
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <windows.h>
#include <boost/thread.hpp>
class ConcurrentCounter {
unsigned int* counters_;
int length_;
#define _SECURE_SCL 0
#include <iostream>
#include <vector>
#include <string>
#include <deque>
#include <algorithm>
#include <numeric>
#include <windows.h>
namespace details {
@Lazin
Lazin / gist:3376627
Created August 17, 2012 07:02
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (PC)

Loosely ordered with the commands I use most towards the top. Sublime also offer full documentation.

Editing

Ctrl+C copy current line (if no selection)
Ctrl+X cut current line (if no selection)
Ctrl+⇧+K delete line
Ctrl+↩ insert line after
@Lazin
Lazin / double_ended_queue.cpp
Last active December 11, 2015 03:59
Playing with Intel's Restricted Transactional Memory.
#include <immintrin.h>
#include <iostream>
#include <thread>
template <class fun>
inline void atomic(fun const& block) {
while(_xbegin() != _XBEGIN_STARTED)
printf("Txn retry\n");
block();
trait Foo {
fn foo(&self);
}
trait Bar : Foo {} // trait is empty
impl MyStruct : Foo {
fn foo(&self) {
// implementation goes here
}
trait Drawable { fn draw(&self); }
trait Printable { fn print(&self); }
impl Circle: Drawable { fn draw(&self) { ... } }
impl Circle: Printable { fn print(&self) { ... } }
// both traits - Printable and Drawable is
// implemented for `Circle`
fn draw_all(shapes: &[@(Drawable+Printable)]) { // invalid syntax in Rust
// suppose we need to accept array of object that both
class Item:
def __init__(self, **kvargs):
self.__dict__.update(**kvargs)
@Lazin
Lazin / gist:7642571
Created November 25, 2013 15:03
Однажды, я написал вот такой код :)
apr_pool_t* mem_pool_; //< local memory pool
apr_mmap_t *mmap_;
apr_file_t *fp_;
apr_finfo_t finfo_;
static log4cxx::LoggerPtr s_logger_;
PersistentPageManager(const char* file_name) {
AprStatusChecker status; // status.count increments on each assign
try {
status = apr_pool_create(&mem_pool_, NULL);