Skip to content

Instantly share code, notes, and snippets.

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

N37R09U3 n37r06u3

🏠
Working from home
  • China
View GitHub Profile
@n37r06u3
n37r06u3 / gist:78eb88ea444822ee04ddf0574065d54e
Created June 30, 2017 07:54 — forked from pulse-/gist:8655893
Django migrate sqlite3 db to postgres - The easy way.
I had this really small problem today. I wanted to migrate one of my small django apps to use postgres, just to make everything easy to manage. Sqlite3 is perfectly fine for the amount of load, however I am really much faster at administering postgres than I am on sqlite3. So I decided to migrate the stuff over.
I tried a few approaches, but what ultimately worked the best and the fastest fo rmy particular problem was to do the following.
Use original SQLITE3 connection in settings.py
1. python manage.py dumpdata > dump.json
(I read some things here about some options you can pass, at the end what just worked was the following)
2. Change DB connection string in settings.py to POSTGRES
#!/usr/bin/python
# -*- coding: utf-8 -*-
# utf-8 中文编码
import glob
import os,sys
import json
reload(sys)
sys.setdefaultencoding('utf-8')
import time, sys,iptc # iptc 包通过 sudo pip install python-iptables 安装
from datetime import datetime
@n37r06u3
n37r06u3 / odoo.conf
Created April 8, 2017 16:00 — forked from ryanc-me/odoo.conf
Sample Odoo/Nginx Config (with dbfilter_from_header support)
# Author: Ryan Cole
# Website: https://ryanc.me
# GitHub: https://github.com/MGinshe
# Usage:
# Place this file in /etc/nginx/sites-enabled/
# Make sure you edit the DOMAIN_HERE and SSL_CERTIFICATE, and DB_FILTER sections
#
# Note: This config file is designed to be used with the Odoo dbfilter_from_header module
# https://apps.openerp.com/apps/modules/9.0/dbfilter_from_header/
@n37r06u3
n37r06u3 / odoo_install.sh
Created April 8, 2017 15:08 — forked from bistaray/odoo_install.sh
Install Odoo v10 Enterprise (with Bista repositories)
#!/bin/bash
################################################################################
# Script for installing Odoo V10 on Ubuntu 16.04, 15.04, 14.04
# Author: Yenthe Van Ginneken
# Adjusted: Ray Carnes
# Assumes you already have an Ubuntu user called "odoo" with a home folder
#-------------------------------------------------------------------------------
# Make a new file:
# sudo nano odoo-install.sh
# Place this content in it and then make the file executable:
@n37r06u3
n37r06u3 / forms.py
Created August 24, 2016 12:39 — forked from oyakata/forms.py
djangoのRegexFieldの使用例
# -*- coding:utf-8 -*-
import re
from django import forms
USERID_REGEX = re.compile(r"^[\w-]+$")
class UserForm(forms.Form):
userid = forms.RegexField(max_length=64, regex=USERID_REGEX)

Crawling Anonymously with Tor in Python

adapted from the article "Crawling anonymously with Tor in Python" by S. Acharya, Nov 2, 2013.

The most common use-case is to be able to hide one's identity using TOR or being able to change identities programmatically, for example when you are crawling a website like Google and you don’t want to be rate-limited or blocked via IP address.

Tor

Install Tor.

using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using System.Windows.Input;
using System.Windows.Threading;
using System.Collections.Generic;
namespace Ownskit.Utils
{
// ==UserScript==
// @name 400gb.com Ads Remover
// @description Yes
// @version 0.1
// @author halfcoder
// @namespace http://github.com/halfcoder
// @include http://www.400gb.com/file/*
// ==/UserScript==
setTimeout(function() {
// This is shamelessly copied from http://stackoverflow.com/questions/263743/how-to-get-cursor-position-in-textarea#answer-3373056
function getInputSelection(el) {
var start = 0, end = 0, normalizedValue, range, textInputRange, len, endRange;
if (typeof el.selectionStart == "number" && typeof el.selectionEnd == "number") {
start = el.selectionStart;
end = el.selectionEnd;
}
else {
range = document.selection.createRange();
if (range && range.parentElement() == el) {

Use Django Fixtures to Automatically Load Data when You Install an App

First, load some data via the admin that should always be there when someone installs the app.

Next, dump that data out into JSON format into a fixture:

$ ./manage.py dumpdata [app_name] > [app_name]/fixtures/initial_data.json