Posts

Showing posts from 2014

Error copying files in Finder of OS X

Image
Problem: I have an SD flash card (8 GB Kingston) and a MacBook Pro 13" (Late 2011 model). I also use external card reader time to time. This problem persisted on all the conditions. The error message was stating: The Finder can’t complete the operation because some data in “” can’t be read or written. (Error code -36) This was happening while copying Photos from my camera (cr2 files). It worked, however, in case of copying files up to 200 MB in total size of batch. It dropped this error message and did stop to copy files upon selecting of lots of RAW files. E.g. all of them and attempting to copy them from a flash drive. Solution: Problem occurred with building miniatures of the CR2 files. Those files are quite heavy photos (25+ MB) and building miniature did take some time. While building those miniatures on both MAC and SD card finder windows it did die. For me it was enough to change the view from icons to list. E.g.: This did solve it for me. Other solution (Suspect

5 most common Rsync command usage examples

Image
rsync is a command for remote sync. It is used to synchronise one location to another in a simple way. Location is meant to be local directory, server or remote web server or whatever accessible by ssh. Advantages of using rsync over other tools is speed and bandwidth requirements. First time rsync copies entire contents of the directory provided and increments changes over next sync times. Command syntax: $ rsync options source destination 1. Synchronising local directories: $ rsync -zvr /tmp/logs/ /tmp/logs1/ building file list ... done created directory /tmp/ logs1 ./ log. log sent 98 bytes received 48 bytes 292.00 bytes/sec total size is 0 speedup is 0.00 $ Used rsync command options here: -z is for compression -v is for verbose output -r is for recursive directory scanning By default rsync does not preserve timestamps.  2. Preserve timestamps and permissions during sync: $ rsync -azvr /tmp/logs/ /tmp/logs

Django adding custom widget to Django Admin

Image
Sometimes you need to get out of standard behaviour of your Django admin. It means expanding its functionality with custom things. In our case we have a model that we want to add a custom html element. Button that must load something via AJAX from another place to be exact. We have a typical Django polls application for simplicity. Here is its structure: First of all we need to create a structure. So here comes our model: # models.py from django.db import models class Poll (models.Model): question = models.CharField(max_length= 200 ) pub_date = models.DateTimeField( 'date published' ) We have to have our django application admin configuration to display that model: # admin.py from django.contrib import admin from polls.models import Poll admin.site.register(Poll) It will look in Django admin like so: You can see polls available here in admin. You can do all the typical things with Polls model. Add/Delete/Edit... Using standard D

Virtualenv for Django

Image
One of main features and troubles for Django projects is the Django version you are using. Example for this would be the occasion of starting project for Django 1.4.x version. Trying to run it under Django 1.7.x would lead to various troubles, counting template changes, misconfiguration errors and so on. Solution is to use virtual environment. The tool for this is called Virtualenv . It is a wrapper for a python interpreter. It enables you to have multiple versions of python packages that run independently. The Virtualenv creates you a standalone environment. Basically it copies and keeps a system Python of yours in a specified directory. All the python packages will be installed there. (In case you have not forgot to activate it first, of course) Lets get started then. We need Virtualenv itself for the first. There are many ways to install it depending on your system . Most obvious to use pip. Your installation command will look something like that: pip install virtualenv Thi

Django CMS custom Plugin ManyToMany fields problems.

Image
Developing a website for Django CMS I have done a plugin. This plugin however have had a problem. It had an m2m field. While selecting images there (It was a gallery plugin). It was not saving it to production. This way main problem with this field was that plugin have displayed m2m choices on a draft page and while storing it to live it fails. Django CMS Pages is built like so it has multiple versions of pages. Each Page model that is changed is stored under new revision. And so plugin is copied and relinked to that page too. So plugin revisions multiply to. For e.g. in case you have a Draft page with two plugins that have model primary key number (pk in future) 12 and 14 accordingly. Say you hit publish changes. Not only PK of Page model rises and data are copypasted into new empty Page model instance. Those plugins are copied to. So mentioned plugins PK would change to 15 and 16 accordingly, assuming 14 is the latest plugin pk. New copied plugins will be linked to new page. Tha

Implementing a Multiple (Radio) Select + “Other” widget in Django

Image
I have had a task to implement Radio Select field with "Other" choice field in a Django Model Form. Here is my implementation in case someone would benefit from it. The idea is to have it all stored to Django's CharField type of data and have a preselected set of fields. We have a model: # models.py class Entry (models.Model): SET_OF_CHOICES = ( ( 'choice1' , 'choice1' ), ( 'choice2' , 'choice2' ), ( 'choice3' , 'choice3' ), ( 'Other' , 'Other Please Specify' ), ) choice = models.CharField(_( "Selected your choice" ), max_length= 250 ) That makes it ready for the set of fields for for our form. We are overriding Model form default field for this type of data (CharField) by intentionally specifying field with the same name. # forms.py from django.forms import ModelForm, ChoiceField, RadioSelect from models import Entry

How to delete a remote git tag

I'm always forgetting this. So decided to put it here for someone's benefit. I have the git tag added by command: git tag -a 1.2 . 0 -m "1.2.0" this means my tags tree will be updated with the tag 1.2.0 and message 1.2.0 Usually it marks the version of the build/release. I now push a tag to origin by command: git push origin --tags It is possible to see it at my repository github tagged. Time now to delete a tag. It can be done by command: git tag -d 1.2 . 0 This will remove a local tag 1.2.0. Leaving origin intact. Pushing tags to origin does not give anything. To remove a remote tag now it is required to execute command: git push origin :refs/tags/ 1.2 . 0 It will remove tag 1.2.0 at origin. This is the only way how to move tags to another commits.

Pillow compile error clang: -Wno-error=unused-command-line-argument-hard-error-in-future fix

Image
I have had a problem with compiling Pillow recently. the error was with Pillow/Pil compilation. pillow install error clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard-error- in -future] Apple updated command line tools. So the cc command was updated too. $ gcc --version Configured with : --prefix= /Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 Apple LLVM version 5.1 (clang- 503.0 . 38 ) (based on LLVM 3.4 svn) Target: x86_64-apple-darwin13. 1.0 Thread model: posix The bug is in GCC. It is quite serious because those flags support will be dropped in future. Fortunately there is a worakround for now: export ARCHFLAGS= "-Wno-error=unused-command-line-argument-hard-error-in-future" It works for Pillow 2.4.0 and I can compile it with Apple LLVM 5.1 (That is current now), as of Xcode 5.1. Hope my findings will help someone.

Django: adding additional Admin static and writing JS snippets for Django Admin

Image
It often gets that you need it because you invent something that is meant to be displayed for admin. E.g. some nasty form field or something. Here is my recipe to add some additional Django static to your admin. Rather than writing a widget , that is more proper way here... I was using a widget already (from another package). So I could not use it properly, at least without a ton of overrides and complexity it leads to. SO I've decided to add the JS functionality to override a lack of backend. First of all we should add the javascript/css like so: # admin.py class MyModelAdmin (admin.ModelAdmin): # admin additions class Media : css = { "all" : ( "css/my_style.css" ,) } js = ( "js/my_script.js" ,) This add should list your files, loaded in the admin . So you can access them and see in the Django admin frontend itself. Like so: Now that your script and style are loaded you could jus

Lightning unofficial cable trick for iOS 7

Image
I have found a hack of how to firs time sync your iphone via unofficial (cheap Chinese) cable. It may be a hint to you if you are buying an iPhone from a second hand without accessories. You will need TADAA! Official Apple cable but not for a lightning port. And another Apple device. The thing is if you connect both your new iPhone or iPad via lightning port and using unofficial cable and ANY of your Apple devices using OFFICIAL Apple cable. It will trust your lightning connected device. Some magic happens and one device connected with official apple cord makes another device connected via official cord too. TADAA. Now you can sync at least once... and use Wi-Fi sync later on... Hopoe it helps you. Comments?