Skip to content

Instantly share code, notes, and snippets.

View sjsakib's full-sized avatar
🦥

Sharfin Jahan Sakib sjsakib

🦥
View GitHub Profile
import socket
port = 8000
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind(('', port))
sock.listen(1)
client_sock, addr = sock.accept()
import socket
host = 'localhost'
port = 8000
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((host, port))
sock.send('Ping!'.encode())
@sjsakib
sjsakib / pre-commit.py
Last active November 24, 2017 09:55
a simple pre-commit git hook
#!/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'])
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')
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
#!/usr/bin/python3
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE',
'projectname.settings')
import django
django.setup()
# Codes to execute...
@sjsakib
sjsakib / loj.py
Created October 12, 2017 05:34
loj.py file so far in Light OJ scraping project
# -*- 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']
@sjsakib
sjsakib / ToggleFileInput.py
Created September 9, 2017 04:21
Toggles input with file line in sublime text. Useful for competative programming
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')")
Any of your information will not be used for any purpose except to send you messages as you subscrbe.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.