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
Any of your information will not be used for any purpose except to send you messages as you subscrbe. |
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 sublime_plugin | |
class TogglePythonFileInputCommand(sublime_plugin.TextCommand): | |
def run(self, edit): | |
reg1 = self.view.find(r"# sys\.stdin = open\('in', 'r'\)", 0) | |
reg2 = self.view.find(r"# import sys", 0) | |
if not reg1.empty(): | |
self.view.replace(edit, reg1, "sys.stdin = open('in', 'r')") |
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
# -*- coding: utf-8 -*- | |
import scrapy | |
from bs4 import BeautifulSoup | |
class LojSpider(scrapy.Spider): | |
name = 'loj' | |
allowed_domains = ['lightoj.com'] | |
start_urls = ['http://lightoj.com/login_main.php'] |
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
#!/usr/bin/python3 | |
import os | |
os.environ.setdefault('DJANGO_SETTINGS_MODULE', | |
'projectname.settings') | |
import django | |
django.setup() | |
# Codes to execute... |
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
from django.core.management.base import BaseCommand | |
from myapp.models import UserProfile | |
class Command(BaseCommand): | |
help = 'Update points of all users' # help text | |
def handle(self, *args, **options): | |
for user in UserProfile.objects.all(): | |
points = 0 |
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
from django.core.management.base import BaseCommand | |
from myapp.models import UserProfile | |
class Command(BaseCommand): | |
help = 'Update points of all users' # help text | |
def add_arguments(self, parser): # it takes a `parser` as an argument | |
parser.add_argument('-s', action='store_true', help='silent') | |
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
#!/usr/bin/python3 | |
import os | |
import datetime | |
from subprocess import check_output | |
# for the first time we'd like to build docs for all the files, | |
# not just the changed files, this line will give us all the files | |
# changed = check_output(['git', 'ls-files']) | |
changed = check_output(['git', 'diff', '--cached', '--name-only']) |
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 socket | |
host = 'localhost' | |
port = 8000 | |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
sock.connect((host, port)) | |
sock.send('Ping!'.encode()) |
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 socket | |
port = 8000 | |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
sock.bind(('', port)) | |
sock.listen(1) | |
client_sock, addr = sock.accept() |
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 socket | |
port = 8000 | |
# we'll send this message before closing connection | |
# so that other side can close connection as well | |
CLOSE = b'--close--' | |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |