Skip to content

Instantly share code, notes, and snippets.

View rririanto's full-sized avatar
🏠
Working from home

Rahmat Ramadhan rririanto

🏠
Working from home
View GitHub Profile
@rririanto
rririanto / package.json
Created March 4, 2021 03:07
Remove Unused CSS for Django Project - package.json
{
"name": "workolio",
"version": "0.1.0",
"dependencies": {},
"devDependencies": {
"chai": "^4.3.0",
"chalk": "^4.1.0",
"cssmin": "^0.4.3",
"grunt": "^1.3.0",
"grunt-cli": "^1.3.2",
@rririanto
rririanto / scraping_baypass.py
Created February 22, 2021 16:21
Bypass & Scraping Websites that has CSS class names change frequently.
class_css = response.css('main[class^="D_"] ::attr(class)').getall()[12]
url = response.css('a[class^="%s"] ::attr(href)'% class_css).get()
print (url)
@rririanto
rririanto / set_translation.py
Created February 20, 2021 00:38
Set Translation
urls.py
============================
from django.urls import path
# Your path of views
from apps.main.views import main, set_language_from_url
urlpatterns = [
...
path("set_language/<str:user_language>/", set_language_from_url, name="set_language_from_url")
@rririanto
rririanto / index.html
Last active February 19, 2021 06:04
Index templates
{% load i18n%}
<title>{% trans "This is the title." %}</title>
{% blocktrans %}This string will have {{ value }} inside.{% endblocktrans %}
<ul id="nav">
<a href='/'>{% trans "Jobs" %}</a>
<a href="{% url 'jobs:companies' %}" class=">{% trans "Startups" %}</a>
</ul>
@rririanto
rririanto / settings.py
Last active February 20, 2021 01:09
Settings Django Translation v1
from django.utils.translation import gettext_lazy as _
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
INSTALLED_APPS = (
...
"translation_manager",
...
)
@rririanto
rririanto / base.py
Last active February 20, 2021 00:53
Settings Django Translation Manager v2
import environ
from django.utils.translation import gettext_lazy as _
ROOT_DIR = environ.Path(__file__) - 3
APPS_DIR = ROOT_DIR.path("apps")
INSTALLED_APPS = (
...
"translation_manager",
...
@rririanto
rririanto / scrape-ads.py
Last active February 1, 2021 03:09
scrape ads
'''
1. Counter digunakan untuk menjumlahkan berapa banyak looping yang terjadi, dimana angka tersebut bisa kita gunakan
Untuk berbagai keperluan.
misalnya terdapat url yang punya page_number dan kita ingin mendapatkan halaman 1,2,3 dst
maka website.com/jobs?keywords=python&page_num=<hasil di taruh di sini 1,2,3>
hasilnya
website.com/jobs?keywords=python&page_num=1
website.com/jobs?keywords=python&page_num=2
website.com/jobs?keywords=python&page_num=3
@rririanto
rririanto / .pre-commit-config.yaml
Created January 27, 2021 11:56
Pre-commits Init
repos:
- repo: git://github.com/pre-commit/pre-commit-hooks
rev: v1.4.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-case-conflict
- id: check-merge-conflict
- id: check-yaml
args: ['--unsafe']
class User(AbstractUser, Timestampable):
id = models.UUIDField(
primary_key=True,
default=uuid.uuid4,
editable=False)
customer = models.ForeignKey(Customer, null=True, blank=True, on_delete=models.SET_NULL)
subscription = models.ForeignKey(Subscription, null=True, blank=True, on_delete=models.SET_NULL)
payment_id = models.CharField(max_length=255, blank=True)
@rririanto
rririanto / AbstractBaseCustomer.py
Last active January 28, 2021 10:41
AbstractBaseCustomer
import uuid
from django.db import models
from django.contrib.auth.models import AbstractUser
from djstripe.models import Customer, Subscription, PaymentMethod
class BaseCustomer(models.Model):
customer = models.ForeignKey(Customer, null=True, blank=True, on_delete=models.SET_NULL)
subscription = models.ForeignKey(Subscription, null=True, blank=True, on_delete=models.SET_NULL)
payment_id = models.CharField(max_length=255, blank=True)
class Meta: