Skip to content

Instantly share code, notes, and snippets.

View mobilestack's full-sized avatar

Tony mobilestack

View GitHub Profile
@mobilestack
mobilestack / chatpdf-zh.ipynb
Created March 25, 2023 11:14 — forked from ninehills/chatpdf-zh.ipynb
ChatPDF-zh.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ninehills
ninehills / chatpdf-zh.ipynb
Last active April 9, 2024 06:40
ChatPDF-zh.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jackschultz
jackschultz / bitcoin_block_difficulty_analysis.py
Created November 12, 2017 23:47
Showing of Bitcoin's Proof of Work difficulty is calculated and changed.
import datetime
###################################################################
#
# Showing the way bits, difficulty, target, and hash work together.
#
###################################################################
print "Calculating target from bits, verifying the block's hash is valid, and verify the calculated difficulty."
@revant
revant / nginx-files.conf
Last active February 12, 2024 10:36
Frappe CORS for nginx
location / {
rewrite ^(.+)/$ $1 permanent;
rewrite ^(.+)/index\.html$ $1 permanent;
rewrite ^(.+)\.html$ $1 permanent;
# Allow CORS for static files
add_header Access-Control-Allow-Origin $cors_origin;
add_header Access-Control-Allow-Methods "GET, OPTIONS";
location ~* ^/files/.*.(htm|html|svg|xml) {
@1kastner
1kastner / reflect.py
Last active April 3, 2024 13:52 — forked from huyng/reflect.py
A simple echo server to inspect http web requests
#!/usr/bin/env python
# Reflects the requests from HTTP methods GET, POST, PUT, and DELETE
# Written by Nathan Hamiel (2010)
from http.server import HTTPServer, BaseHTTPRequestHandler
from optparse import OptionParser
class RequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
@miztiik
miztiik / setup-headless-selenium-xvfb.sh
Last active May 23, 2023 20:00
Script to setup headless Selenium (uses Xvfb & Firefox) in Redhat
pip install selenium
pip install xvfbwrapper
yum install -y firefox
# Install the geckodriver
cd /tmp
curl -SO https://github.com/mozilla/geckodriver/releases/download/v0.11.1/geckodriver-v0.11.1-linux64.tar.gz | tar zxv - -C /usr/sbin
yum install -y xorg-x11-server-Xvfb
# yum install -y xorg-x11-Xvfb
# pip install pyvirtualdisplay
@brbsix
brbsix / pyqt5_scraper.py
Created June 18, 2016 05:21
PyQt5 Scraper (Basic Example)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Sample scraper script
See: https://impythonist.wordpress.com/2015/01/06/ultimate-guide-for-scraping-javascript-rendered-web-pages/
"""
# standard imports
import sys
@havencruise
havencruise / setup_ec2_py27_mod_wsgi.sh
Last active June 9, 2018 01:55
Django + Python2.7 + Apache setup for AWS EC2 with mod_wsgi A how-to on setting up Python 2.7, Django and mod_wsgi, and using Python 2.7 with virtual_env(which is the right thing to do) on Amazon EC2 instances. .. .. .. Why? - Because Amazon EC2 instances usually come with Python 2.6 by default.
# You will need to run these with superuser permissions.
# Either prefix `sudo` to all commands, or switch user
# Be very careful when you switch user
sudo su - root
# Update all the packages
yum update
# Install the basics - python27, gcc, svn, git, httpd, make, uuid
@estebistec
estebistec / fields.py
Last active October 13, 2016 05:11
Django-REST-framework list serializer
def nested_from_native(nested_field, data):
if isinstance(nested_field, serializers.BaseSerializer):
return nested_field.from_native(data, None)
return nested_field.from_native(data)
class ListField(fields.WritableField):
def __init__(self, item_field, *args, **kwargs):
super(ListField, self).__init__(*args, **kwargs)
@eerien
eerien / forms.py
Last active February 2, 2023 23:12
Comma Separated Values Form Field for Django. There are CommaSeparatedCharField, CommaSeparatedIntegerField.
from django import forms
from django.core import validators
from django.core.exceptions import ValidationError
class MinLengthValidator(validators.MinLengthValidator):
message = 'Ensure this value has at least %(limit_value)d elements (it has %(show_value)d).'
class MaxLengthValidator(validators.MaxLengthValidator):
message = 'Ensure this value has at most %(limit_value)d elements (it has %(show_value)d).'