Skip to content

Instantly share code, notes, and snippets.

@MasterAlish
MasterAlish / solution_on_bash_sctipt
Created November 1, 2012 04:10
Задача из учебника по ПХП
#!/bin/bash
in="Теперь пора всем хорошим людям прийти на помощь стране"
s=($in)
out=${s[1]/п/П}\ ${s[0]/Т/т}\ ${s[8]}\ ${s[5]}\ ${s[6]}\ ${s[7]}\ ${s[2]}\ ${s[3]}\ ${s[4]}
echo A. $in
echo B. $out
@MasterAlish
MasterAlish / rectangularGrid.cpp
Created August 22, 2013 19:03
Solution for "sunloverz / gist:6309925" on c++
#include <stdio.h>
class RectangularGrid{
public:
long long countRectangles(int n, int m){
long long sum=0;
for(int i_n=1; i_n<=n; i_n++)
for(int i_m=1; i_m<=m; i_m++)
if(i_m!=i_n)
sum+=(m-i_m+1)*(n-i_n+1);
@MasterAlish
MasterAlish / rectangularGrid.rb
Created August 22, 2013 19:06
Solution for "sunloverz / gist:6309925" on ruby
class RectangularGrid
def countRectangles(n,m)
sum = 0
for i_n in 1..n
for i_m in 1..m
if i_m != i_n
sum = sum + (m-i_m+1)*(n-i_n+1)
end
end
end
@MasterAlish
MasterAlish / gist:7226122
Created October 30, 2013 02:06
olymp.krsu.248
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Solution {
private final double y2;
private final double y1;
private final double x2;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Solution {
@MasterAlish
MasterAlish / olymp.krsu.147
Created January 4, 2014 10:38
olymp.krsu.147
import java.util.Scanner;
public class Solution {
public static void main(String[] arg){
int N, M;
int[] A;
Scanner in = new Scanner(System.in);
N = in.nextInt();
M = in.nextInt();
@MasterAlish
MasterAlish / html_input_dict.py
Last active June 29, 2020 17:58
Django html input array and dict
def get_html_input_dict(self, query_dict, param):
dictionary = {}
regex = re.compile('%s\[([\w\d_]+)\]' % param)
for key, value in query_dict.items():
match = regex.match(key)
if match:
inner_key = match.group(1)
dictionary[inner_key] = value
return dictionary
@MasterAlish
MasterAlish / pagination.py
Created April 10, 2015 10:16
Pagination python
# total - total pages count
# page - current page
# neighbour_count - nighbour pages count, from each side
#
# 'first' - link to first page
# 'last' - link to last page
def pagination(total, page=1, neighbour_count=2):
result = []
if page-neighbour_count > 2:
@MasterAlish
MasterAlish / paginate_queryset.py
Last active August 29, 2015 14:18
Paginate every models list page
# define in settings.py to able to use request in templates
TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.request',
'django.contrib.auth.context_processors.auth',
)
# in templatetags
@register.inclusion_tag("gist:pagination_pages.html")
@MasterAlish
MasterAlish / letter_insert.js
Created September 15, 2015 16:28
JS insert letter into input at the selection
insert_letter: function (input_id, letter) {
var elem = document.getElementById(input_id);
var selectionStart = elem.selectionStart;
var selectionEnd = elem.selectionEnd;
var start = elem.value.substring(0, selectionStart);
var finish = elem.value.substring(selectionEnd, elem.value.length);
elem.value = start + letter + finish;
elem.focus();
elem.selectionStart = selectionStart + 1;
elem.selectionEnd = selectionStart + 1;