Skip to content

Instantly share code, notes, and snippets.

View reflechant's full-sized avatar

Roman Gerasimov reflechant

  • Amsterdam
View GitHub Profile
import random
import collections
import operator
import itertools
random.seed()
l = [random.randint(1, 18) for i in range(8)]
#l = [4, 8, 18, 18, 10, 3, 11, 18]
print(*l)
import random
import operator
random.seed()
A, B, N = map(int, input().split())
# заполняем список случайными числами:
l = [random.randint(A, B) for i in range(N)]
# сортируем по неубыванию, возвращая список пар чисел (индекс, число)
m = sorted(enumerate(l), key=operator.itemgetter(1))
# создаём список дистанций между отсортированными числами
package main
import (
"bufio"
"flag"
"fmt"
"io"
"log"
"os"
"strings"
@reflechant
reflechant / parallel_benchmark.go
Last active August 29, 2017 21:17
unfinished benchmark of parallel calculation in Go (trying to rewrite https://habrahabr.ru/post/336684/)
package main
import (
"math"
"time"
"fmt"
)
type Point struct {
x float64
@reflechant
reflechant / ethernet_raw.c
Last active June 27, 2017 10:59
Receiver MAC level packets from network
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <errno.h>
#include <string.h>
#include <inttypes.h>
#include <linux/if_packet.h>
#include <linux/if_ether.h>
// #include <netpacket/packet.h>
set nocompatible
autocmd FileType python set expandtab
syntax on
" set number
set tabstop=4
set autoindent
set shiftwidth=4
" set cursorline
set showmatch
@reflechant
reflechant / rasp.py
Last active August 10, 2016 07:35
Консольный клиент для сервиса Яндекс.Расписания
#!/usr/bin/env python3
import requests
import sys
import datetime as dt
SECRET_KEY = """ Ключ можно получить здесь: https://tech.yandex.ru/rasp/raspapi/ """
p = {"Белорусский вокзал": "s2000006",
"Шереметьево": "s9600213"
@reflechant
reflechant / crc32.py
Last active August 10, 2016 07:15
Get CRC32 checksum of a file
#!/usr/bin/env python
import sys
import zlib
def main():
with open(sys.argv[1], 'rb') as f:
data = f.read()
print(hex(zlib.crc32(data)))
@reflechant
reflechant / freq.py
Last active January 24, 2016 19:49
Generate 440Hz (note A) wave file on Windows with Python
import mmap
import winsound as ws
import struct as st
from math import sin, cos, radians
from random import randint
# in RIFF format (and therefore in WAVE) ALL NUMBERS ARE LITTLE ENDIAN
FILE_SIZE = 44100*10+44 # bytes
#!/usr/bin/env python3
import requests
import sys
import datetime as dt
SECRET_KEY = "get it yourself @ yandex"
p = { "Одинцово" : "s9600721",
"Голицыно": "s9602265",