Skip to content

Instantly share code, notes, and snippets.

View habibutsu's full-sized avatar

Alexander Verbitsky habibutsu

View GitHub Profile
@habibutsu
habibutsu / tail.sh
Created April 19, 2013 14:40
Output the last part of files via http
#!/bin/bash
if [ -z "$1" ]; then
echo "Usage $0 <url to file>"
exit 1
fi
BASE_URL=$(dirname $1)
FILE=$(basename $1)
@habibutsu
habibutsu / gist:5618756
Created May 21, 2013 10:07
Execute command in bash with copy stderr into variable and stdout into stdout of script
function exec_cmd {
exec 3>&1
error=$( { $@ 1>&3; } 2>&1 )
exec 3>&-
if [ "${error}" ]; then
echo "[ERROR] ${error}"
exit 1
fi
}
@habibutsu
habibutsu / imports_examples.py
Last active December 24, 2015 16:39
Different way to import in pythons
# Varaian 1
from package import module_with_some_name1, module_with_some_name2, \
module_with_some_name3, module_with_some_name4, module_with_some_name5, \
module_with_some_name6, module_with_some_name7
# Variant 2
from package import module_with_some_name1, \
module_with_some_name2, \
@habibutsu
habibutsu / ansi_c.cpp
Created October 19, 2013 23:48
Different ways to copy file
#include <iostream>
#include <cstdio> // fopen, fclose, fread, fwrite, BUFSIZ
#include <ctime>
using namespace std;
int main() {
clock_t start, end;
start = clock();
// BUFSIZE default is 8192 bytes
@habibutsu
habibutsu / split_file.py
Created December 11, 2013 11:35
Split file by specific string
import mmap
import os
from sys import stdout
from sys import exit
# If length is 0, the maximum length of the map is the current size of the file
FIND_BUFFER_SIZE = 0
READ_BUFFER_SIZE = 100
SEARCH_STRING = "substring3.1"
@habibutsu
habibutsu / inotify_example.py
Created December 13, 2013 14:26
Example a work with inotify in Python
import os
import sys
import struct
from collections import namedtuple
from ctypes import\
CDLL,\
CFUNCTYPE,\
c_int,\
c_char_p,\
@habibutsu
habibutsu / pika_basic_publish.py
Last active August 29, 2015 13:57
Amqp proxy
import pika
import logging
import pickle
import json
AMQPS = {
'test': {
'host': '127.0.0.1',
'port': 5672,
'userid': 'test',
% Compile:
% erlc +debug_info amqp_consumer.erl;
% Run:
% erl -noshell -s amqp_consumer consume -s init stop
-module(amqp_consumer).
-export([consume/0]).
-include_lib("amqp_client/include/amqp_client.hrl").
@habibutsu
habibutsu / nvidia-340.76-kernel-4.0.patch
Last active August 31, 2015 08:55
Patch for NVIDIA driver 340.76 for Linux 4.0
Index: kernel/nv-pat.c
===================================================================
--- kernel/nv-pat.c.orig
+++ kernel/nv-pat.c
@@ -35,8 +35,13 @@ static inline void nv_disable_caches(uns
unsigned long cr0 = read_cr0();
write_cr0(((cr0 & (0xdfffffff)) | 0x40000000));
wbinvd();
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 20, 0)
*cr4 = read_cr4();
@habibutsu
habibutsu / elixir_to_erlang.erl
Last active August 10, 2019 16:46
Elixir to Erlang
% erl -pa /usr/share/elixir/1.0.5/lib/*/ebin -elixir ansi_enabled true
application:ensure_all_started(elixir),
rr("/usr/share/elixir/1.0.5/lib/elixir/src/elixir.hrl").
% A simplified version of 'Elixir.Code':eval_string/2
% https://github.com/elixir-lang/elixir/blob/v1.2.0/lib/elixir/lib/code.ex#L159
EvalString = fun(String, Binding) ->
% Converts a given string (char list) into quote expression
% https://github.com/elixir-lang/elixir/blob/v1.2.0/lib/elixir/src/elixir.erl#L252