Skip to content

Instantly share code, notes, and snippets.

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#define SIZE 12
#pragma pack(1)
struct Data
{
#include <stdio.h>
#include <string.h>
int cmp(int p, int perm)
{
if((p & 1) && !(perm & 1))
return 0;
if(((p >> 1) & 1) && !((perm >> 1) & 1))
return 0;
if((p >> 2) && !(perm >> 2))
@theasder
theasder / totalsize
Last active December 25, 2015 00:39
#include <stdio.h>
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char* argv[])
{
DIR *catalog = opendir(argv[1]);
#include <stdio.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include <stdlib.h>
int main(void)
{
int bytes = 0, end, i, displacement = 0, old_displacement = 0;
#include <signal.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(int argc, char** argv)
@theasder
theasder / gist:7894534
Last active December 30, 2015 22:29
Побайтовое считывание
void readbyte(int f, void *p, unsigned int size) {
int i, status;
unsigned char* ptr = p;
for(i = 0; i < size; i++) {
status = -1;
while(status != 1) // считываем до тех пор, пока рид действительно не считает 1 байт
status = read(f, ptr, 1); // записываем результат считывание, -1 если ошибку выдали
ptr++; // увечиваем на один байт указатель места считывания
}
@theasder
theasder / gist:7895405
Last active December 30, 2015 22:39
12-3
#include <signal.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/wait.h>
#include <sys/stat.h>
int main(int argc, char** argv)
{
@theasder
theasder / psort.c
Last active December 31, 2015 18:59
Parallel selection sort
#include <signal.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <limits.h>
@theasder
theasder / translit.py
Created January 27, 2014 09:07
Translit
# -*- coding: utf-8 -*-
def translit(s):
symbols = (u"абвгдеёзийклмнопрстуфхъыьэюАБВГДЕЁЗИЙКЛМНОПРСТУФХЪЫЬЭЬЬЮ",
u"abvgdeezijklmnoprstufh'y'euABVGDEEZIJKLMNOPRSTUFH'Y'EU")
tr = {ord(a):ord(b) for a, b in zip(*symbols)}
vac = {u'я': 'ya', u'ж': 'zh', u'ц': 'ts', u'ч': 'ch', u'ш': 'sh', u'щ': 'sch', u'Я': 'Ya', u'Ч': 'Ch', u'Ш': 'Sh', u'Щ': 'Sch', u'Ж': 'Zh', u'Ц': 'Ts'}
s = s.translate(tr)
s = ''.join([vac.get(c, c) for c in s])
return s
@theasder
theasder / yql_py.py
Created January 31, 2014 09:23
Working with YQL through python
import urllib
import urllib2
import ast
def get_info(req):
base_url = "http://query.yahooapis.com/v1/public/yql?q="
value = urllib.pathname2url(req)
rest = "&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback="
response = urllib2.urlopen(base_url + value + rest)
html = response.read()