Skip to content

Instantly share code, notes, and snippets.

@gordinmitya
gordinmitya / nginx.conf
Created September 16, 2019 19:42
Lab4 Nginx configuration: serve static files, proxy other requests to python application.
http {
server {
listen 80 default_server;
listen [::]:80 default_server;
location ~ \.(ico|png|jpg) {
root /www/media;
}
location / {
@gordinmitya
gordinmitya / download_thread.py
Last active September 17, 2019 10:12
distributed systems: lab 2
class DownloadThread(Thread):
def __init__(self, url):
super().__init__()
self.url = url
def run(self):
handle = urllib.request.urlopen(self.url)
fname = os.path.basename(self.url)
with open(fname, "wb") as f_handler:
@gordinmitya
gordinmitya / CalcActivity.java
Created May 29, 2019 09:50
Пример задания обработчика нажатия нескольким кнопкам. Калькулятор.
private View.OnClickListener numberClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.button0:
// обработка нажатия на 0
break;
// остальные кнопки …
}
}
@gordinmitya
gordinmitya / Main.java
Created January 24, 2019 16:54
HashSet example with equals and hashCode overriding
package ru.gordinmitya;
import java.util.*;
class Product {
private String name;
private int price;
Product(String name, int price) {
this.name = name;
private Bitmap loadFromSvg(String name) {
File file = new File(getDirectory(), name + ".svg");
if (!file.exists()) return null;
Drawable drawable = VectorDrawableCompat.createFromPath(file.getAbsolutePath());
if (drawable == null) return null;
Bitmap bitmap = Bitmap.createBitmap(
drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight(),
class CityCell: BaseCell {
override class var id: String {return "CityCell"}
var checkedImage: UIImageView = {
let iv = UIImageView()
iv.contentMode = .scaleAspectFill
iv.clipsToBounds = true
iv.translatesAutoresizingMaskIntoConstraints = false
iv.heightAnchor.constraint(equalToConstant: 20).isActive = true
iv.widthAnchor.constraint(equalToConstant: 20).isActive = true
iv.isHidden = true
//
// ComputerDetailViewController.swift
// Computers
//
// Created by Гоша Бодров on 24.07.2018.
// Copyright © 2018 Гоша Бодров. All rights reserved.
//
import UIKit
@gordinmitya
gordinmitya / container.c
Last active June 25, 2018 16:17
super tiny linux container via copy mechanism with cgroup restrictions, internet between container and host and loop device
#define _GNU_SOURCE
#include <sched.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
#define STACK_SIZE (1024 * 1024)
#include <sys/types.h>
#include <unistd.h>
@gordinmitya
gordinmitya / main.cpp
Last active June 25, 2018 17:06
generate binary files with x64 pointers
#include <cstdio>
#include <cstdlib>
#define PTYPE int
#define COUNT 105000 // empiric const to make 40M file
#define BUFFER_SIZE 10
#define VARIATION 500100 // allocate "huge" piece of memory
int main() {
FILE *orderedFile = fopen("ordered.bin", "wb");
val spark = org.apache.spark.sql.SparkSession.builder
.master("local")
.appName("Spark CSV Reader")
.getOrCreate
val df = spark.read
.format("csv")
.option("header", "false") //reading the headers
.option("mode", "DROPMALFORMED")
.schema(StructType(List(
StructField("polarity", IntegerType, nullable = false),