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
@pulse-
pulse- / gist:8655893
Created January 27, 2014 19:44
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
@MattSurabian
MattSurabian / JS Quiz Answer Explanations.md
Last active October 11, 2023 19:38
My attempt to explain the answers for David Shariff's feelings hurting JS quiz found at: davidshariff.com/js-quiz/

Are your feelings hurt?

If you rushed through David Shariff's JS Quiz or are just new to JS they might be. I know mine were. After I dried my eyes, I took the quiz again, this time very slowly trying to get at the meat behind each answer. Below is my attempt to explain each question's answer and offer some interesting permutations so that others can move beyond their hurt feelings and come out the other side better JS developers.

I initially thought I'd turn this into a blog post but think it's probably better as a gist.

Question #1

Don't over think it.

var foo = function foo() {
@halfcoder
halfcoder / 400gb.user.js
Created March 27, 2014 15:27
400gb.com Ads Remover
// ==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() {
@calebwoods
calebwoods / nginx.conf
Created May 10, 2014 20:18
Sample Nginx config for deployment of Angular.js app
server { listen 80;
server_name example.com;
access_log /var/log/example.com/nginx.access.log;
error_log /var/log/example.com/nginx.error.log;
root /var/www/apps/example.com/public;
charset utf-8;
location / {
rewrite ^ https://$host$request_uri? permanent;
}
@cansadadeserfeliz
cansadadeserfeliz / admin.py
Last active April 17, 2019 07:06
Django: add custom button to admin change list view
class BasicAdmin(admin.ModelAdmin):
# ...
def get_urls(self):
urls = super(BasicAdmin, self).get_urls()
my_urls = patterns(
'',
(r'^download_as_xls/$', self.download_as_xls_view)
)
return my_urls + urls
@greatghoul
greatghoul / event.js
Last active March 15, 2024 07:28
Chrome Extension Example - Popup Panel
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.windows.create({
url: "panel.html",
width: 320,
height: 480,
type: 'panel'
});
});
@sveinn-steinarsson
sveinn-steinarsson / get_pipeline_urls.py
Created July 14, 2014 12:51
Use django pipeline in Class Media (for example in admin.py)
from django.contrib.staticfiles.storage import staticfiles_storage
from pipeline.packager import Packager
from pipeline.conf import settings
def get_pipeline_urls(package_type, package_name):
packager = Packager()
package = packager.package_for(package_type, package_name)
if settings.PIPELINE_ENABLED:
return ( staticfiles_storage.url(package.output_filename), )
@cjus
cjus / sample-nginx.conf
Last active July 12, 2023 14:59
AngularJS Nginx and html5Mode
server {
server_name yoursite.com;
root /usr/share/html;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
}
@KhepryQuixote
KhepryQuixote / PyTorStemPrivoxy.md
Last active January 18, 2025 16:46
Python script to connect to Tor via Stem and Privoxy, requesting a new connection (hence a new IP as well) as desired.

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.

@guillaumepiot
guillaumepiot / forms.py
Last active March 28, 2019 11:53
DJANGO CookBook - File type validation in form
# Tested in Django 1.6
class ImportForm(forms.Form):
csv_file = forms.FileField(label=_('Select CSV file'))
def clean_csv_file(self):
f = self.cleaned_data['csv_file']
if not f.content_type in ['text/csv',]:
raise forms.ValidationError(_("The file type is not accepted."))