Skip to content

Instantly share code, notes, and snippets.

View joshyu's full-sized avatar
💭
I may be slow to respond.

Josh Yu joshyu

💭
I may be slow to respond.
  • dalian,Liaoning, China
  • 02:03 (UTC +08:00)
View GitHub Profile
@joshyu
joshyu / remove_apt_cache
Last active March 9, 2022 10:24 — forked from marvell/remove_apt_cache
Remove APT cache (for Dockerfile)
apt-get clean autoclean
apt-get autoremove --yes
rm -rf /var/lib/{apt,dpkg,cache,log}/
@joshyu
joshyu / check_link.py
Created February 23, 2022 07:28 — forked from hackerdem/check_link.py
A simple python script to check broken links of a wesite
@joshyu
joshyu / 00_OSX_Docker_Machine_Setup.md
Created January 7, 2022 08:18 — forked from retraut/00_OSX_Docker_Machine_Setup.md
Use native virtualization on OS X docker with xhyve

What this?

So one of the painful points of using docker on OS X is that you need to run a virtualbox VM, which often suffers from performance issues. With xhyve, a OS X virtualization system, and docker-machine-xhyve you can now have docker use the native OS X hypervisor to run containers.

No more dealing with virtualbox shenanigans!

In this script, I've also set up a way to autoconfigure terminal sessions to load docker's environment vars (dependent on docker-machine) so you do not have to run eval $(docker-machine env whatever) every time you open a new terminal window.

Requirements

@joshyu
joshyu / readme.md
Last active August 16, 2021 01:40
detect internal component when clicking on webcomponent

When we want to detect which internal component we are clicking on some webcomponent,we can use event.composed to check whether the event is broadcasted through a webcomponent, and then check the array list returned from event.composedPath() to look up the DOM, if found then we can confirm we are clicking on the specified DOM node and do some specific things.

https://developer.mozilla.org/en-US/docs/Web/API/Event/composedPath

@joshyu
joshyu / django_task_queue.md
Created July 16, 2021 07:04 — forked from tapanpandita/django_task_queue.md
Task queuing in Django with ZeroMQ

Task queuing in Django with ZeroMQ

Introduction

Here at Glitterbug Tech, Django is the lifeline of everything we make and we are big fans! Django doesn't get in the way and lets us write the language we love, python, while providing an amazing set of tools that makes creating web applications fast and fun. But, as you know, code is executed synchronously before you can send back a response. Which means when you are generating that report from your database which has a million rows, your client has to wait for a response while your application huffs and puffs trying to get everything ready (Unless he times out, in which case you receive angry calls while you try to explain what "502 Bad Gateway" means). Sometimes you just want to make your site more responsive by pushing time consuming tasks in the background ("Your comment has been posted!" while a zmq process works in the backend adding it to your db/caching layer/pushing it to followers/creating rainbows). Wha

@joshyu
joshyu / simple_http_server_cors.py
Created June 2, 2021 03:06 — forked from khalidx/simple_http_server_cors.py
Python SimpleHTTPServer with CORS
#!/usr/bin/env python
# Usage: python cors_http_server.py <port>
try:
# try to use Python 3
from http.server import HTTPServer, SimpleHTTPRequestHandler, test as test_orig
import sys
def test (*args):
test_orig(*args, port=int(sys.argv[1]) if len(sys.argv) > 1 else 8000)
@joshyu
joshyu / svg_sprites.md
Created April 26, 2021 01:57 — forked from darsain/svg_sprites.md
How to use SVG sprites in img[src] and css backgrounds

To make this work in CSS:

background: url('images.svg#chart');

or img:

<img src="images.svg#chart">
@joshyu
joshyu / workbook.md
Created January 4, 2021 14:47 — forked from leisurelicht/workbook.md
Export queryset to Excel workbook
from django.http import HttpResponse
from .utils import queryset_to_workbook

def download_workbook(request):
    queryset = User.objects.all()
    columns = (
        'first_name',
        'last_name',
        'email',
@joshyu
joshyu / admin.py
Created September 15, 2020 07:31 — forked from aaugustin/admin.py
Read-only ModelAdmin for Django
from django.contrib import admin
class ReadOnlyModelAdmin(admin.ModelAdmin):
"""
ModelAdmin class that prevents modifications through the admin.
The changelist and the detail view work, but a 403 is returned
if one actually tries to edit an object.
@joshyu
joshyu / settings_test_snippet.py
Created April 21, 2020 10:06 — forked from NotSqrt/settings_test_snippet.py
Another shot at this problem ..
class DisableMigrations(object):
def __contains__(self, item):
return True
def __getitem__(self, item):
return "notmigrations"
MIGRATION_MODULES = DisableMigrations()