This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CheckboxChoiceWithNumberInput(forms.widgets.CheckboxChoiceInput): | |
def render(self, name=None, value=None, attrs=None, choices=()): | |
if self.id_for_label: | |
label_for = format_html(u' for="{0}"', self.id_for_label) | |
else: | |
label_for = u'' | |
return format_html(u'{1}<label{0}> {2}</label> <input type="number" value="0" name="{3}_number[{4}]"/>', label_for, self.tag(), self.choice_label, self.name, self.choice_value) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); |