Skip to content

Instantly share code, notes, and snippets.

View pimiento's full-sized avatar

Pavel pimiento

View GitHub Profile
public class Graph {
private int V;
private int E;
private Bag<Integer>[] adj; // adjacency list
//create a V-vertex graph with no edges
public void Graph(int V) {
this.V = V;
this.E = 0;
adj = (Bag<Integer>[])new Bag[V];
@pimiento
pimiento / jpegs.php
Created December 11, 2015 07:46 — forked from oxpa/jpegs.php
chatlogs parsing
<?php
date_default_timezone_set('UTC');
echo '<html>';
$request=explode('/',$_SERVER['SCRIPT_NAME'],3);
$log_url=$request[2];
if (empty($log_url)) {
$upper="[email protected]/".date('o/m')."/";
$log_url="[email protected]/".date('o/m/d').".html";
};
$log = @file_get_contents("http://chatlogs.jabber.ru/${log_url}");
@pimiento
pimiento / spyral.py
Last active September 28, 2016 19:16
#!/usr/bin/env python3
check_results = {
5: """
1 2 3 4 5
16 17 18 19 6
15 24 25 20 7
14 23 22 21 8
13 12 11 10 9""",
7: """
def flattener(l):
"""
flattener convert a list of lists to a flat list of values
it is a recursive function:
- outcase: a non-iterable value of l
- body: iterate through sublists in l and extend the result of flattener(sublist)
:param list l: a list of lists with any values
:return: a flat list of values
"""
import sys
import heapq
from collections import Counter
class Entry(object):
def __init__(self, freq=0, char=None):
self.freq = freq
self.char = char
if char is None:
#include <cstddef> // size_t
#include <cstring>
struct String {
String(const char *str = "");
String(size_t n, char c);
~String();
String(const String &other);
@pimiento
pimiento / points.py
Last active September 28, 2018 08:41
#!/usr/bin/env python3
import sys
import math
import itertools
def degree2radian(deg):
return deg * (math.pi / 180)
def get_distance(x_a, y_a, x_b, y_b):
return math.hypot(x_b - x_a, y_b - y_a)
# 1.
def left_anti(a: list, b: list) -> list:
sa = set(a) # O(N_alogN_a)
sb = set(b) # O(N_blogN_b)
result = list(sa - sb) # O(N_a)
return result # O((N_a+N_b)log(N_a+N_b)) -> O(NlogN)
assert left_anti([1, 2, 3, None], [None]) == [1, 2, 3]
assert left_anti([], [1, 2, 3]) == []
class ExampleMiddleware:
# get_response это call-back
def _init_(self, get_response):
self.get_response = get_response
def _call_(self, request):
# Код, который будет вызываться для каждого request-а до вызова view-хи
response = self.get_response(request)
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'me.settings')
try:
from django.core.management import execute_from_command_line