This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def bulk_upsert(model, fields, values, by): | |
""" | |
Return the tuple of (inserted, updated) ids | |
""" | |
result = (None, None) | |
if values: | |
stmt = """ | |
WITH data_set AS ( | |
INSERT INTO %s (%s) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UPDATE table SET field = CONVERT(CAST(CONVERT(field USING latin1) AS BINARY) USING utf8) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE IF NOT EXISTS `country` ( | |
`id` int(11) NOT NULL AUTO_INCREMENT, | |
`iso` char(2) NOT NULL, | |
`name` varchar(80) NOT NULL, | |
`nicename` varchar(80) NOT NULL, | |
`iso3` char(3) DEFAULT NULL, | |
`numcode` smallint(6) DEFAULT NULL, | |
`phonecode` int(5) NOT NULL, | |
PRIMARY KEY (`id`) | |
) ENGINE=MyISAM DEFAULT CHARSET=latin1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OCMDBMaintenanceCreate(CreateView): | |
template_name = 'ocmdb_maintenance/create.html' | |
form_class = MaintenanceForm | |
model = OCMDB_MaintenanceCI | |
success_url = reverse_lazy('ocmdb_maintenance_list') | |
object = None | |
def get(self, request, *args, **kwargs): | |
form_class = self.get_form_class() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OCMDBMaintenanceCreate(CreateView): | |
template_name = 'ocmdb_maintenance/create.html' | |
form_class = MaintenanceForm | |
model = OCMDB_MaintenanceCI | |
success_url = reverse_lazy('ocmdb_maintenance_list') | |
object = None | |
def get(self, request, *args, **kwargs): | |
form_class = self.get_form_class() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.utils import simplejson | |
from django.http import HttpResponse | |
class JsonResponse(HttpResponse): | |
""" | |
JSON response | |
""" | |
def __init__(self, content, mimetype='application/json', status=None, content_type=None): | |
super(JsonResponse, self).__init__( | |
content=simplejson.dumps(content), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user_agent = "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36" | |
proxy = { | |
'network.proxy.type': 1, | |
'network.proxy.http': ip, | |
'network.proxy.http_port': port, | |
'network.proxy.ssl': ip, | |
'network.proxy.ssl_port': port, | |
'network.proxy.socks': ip, | |
'network.proxy.socks_port': port, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
import sys | |
# periodo, cedula, carrera(200), materia, seccion(U), nota(EQ) | |
materias = ['EF3106', 'EF3301', 'EF3305', 'EF2420', 'EF2413', 'EF2415', 'EF2414', 'EF2417', 'EF2419', | |
'EF2418', 'EF1426', 'EF2404', 'EF2411', 'EF2408', 'EF2416', 'EF3302', 'EF2410', 'EF2403', 'EF3312', 'EF1424'] | |
f = open(sys.argv[1], 'rb') | |
print sys.argv[1] | |
print sys.argv[2] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
import sys | |
# periodo, cedula, carrera(200), materia, seccion(U), nota(EQ) | |
materias = ['EF3106', 'EF3301', 'EF3305', 'EF2420', 'EF2413', 'EF2415', 'EF2414', 'EF2417', 'EF2419', | |
'EF2418', 'EF1426', 'EF2404', 'EF2411', 'EF2408', 'EF2416', 'EF3302', 'EF2410', 'EF2403', 'EF3312', 'EF1424'] | |
f = open(sys.argv[1], 'rb') | |
print sys.argv[1] | |
print sys.argv[2] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
"""Compare two aligned images of the same size. | |
Usage: python compare.py first-image second-image | |
""" | |
import sys | |
from scipy.misc import imread | |
from scipy.linalg import norm |
NewerOlder