http://www.cyberciti.biz/tips/nohup-execute-commands-after-you-exit-from-a-shell-prompt.html
ruby csv excel gibberish
From:
http://blog.poyi.tw/blog/2014/05/06/ruby-csv-file/
export_to_csv_string 匯出csv的string格式再利用send_data下載
head = ‘EF BB BF’.split(‘ ‘).map{|a|a.hex.chr}.join() # 加入BOM,解決excel中文亂碼
csv_string = CSV.generate(csv = head) do |csv|
csv << header
csv << body
end
# > csv_string.encoding 執行這句會發現預設編碼為ACSII
csv_string.force_encoding(‘big5’)
# BOM也可以這樣加 csv_string = “\xEF\xBB\xBF#{csv_string}”
# 若不需要調整格式就直接下載
send_data csv_string
convert_to_wide_word 大小寫英文數字轉全形字元
def self.convert_to_wide_word(text)
text.gsub(/[a-v]/){|a|(a.ord + 41608).chr(‘big5’).encode(‘utf-8’)}
.gsub(/[w-z]/){|a|(a.ord + 41673).chr(‘big5’).encode(‘utf-8’)}
.gsub(/[A-Z]/){|a|(a.ord + 41614).chr(‘big5’).encode(‘utf-8’)}
.gsub(/[0-9]/){|a|(a.ord + 41599).chr(‘big5’).encode(‘utf-8’)}
end
convert_to_wide_word(“0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ”)
=> “0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKL
MNOPQRSTUVWXYZ”
cocoapods undefined symbols and duplicate symbols
delete Pod directory, Podfile.lock, *.xcworkspace
Pod install
Edit Scheme (which is on the right of stop button) -> Build -> Add Pods before our project if the Pods not shown
Add origin project Search Path & Other Linker Flags with $(inherited)
Change Build Active Architecture Only to No
http://stackoverflow.com/questions/5303933/xcode4-linking-problem-file-was-built-for-archive-which-is-not-the-architecture
django model speedup
django Elastic Beanstalk
Opswork
https://github.com/poise/poise-python
Elastic Beanstalk
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-django.html
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/installing-ebcli.html
Good tutorial:
https://realpython.com/blog/python/deploying-a-django-app-to-aws-elastic-beanstalk/
Below are simple notes.
eb init
Default region
Choosing the region closest to your end users will generally provide the best performance. Check out this map if you’re unsure which to choose.
Credentials
Next, it’s going to ask for your AWS credentials.
Here, you will most likely want to set up an IAM User. See this guide for how to set one up. If you do set up a new user you will need to ensure the user has the appropriate permissions. The simplest way to do this is to just add “Administrator Access” to the User. (This is probably not a great choice for security reasons, though.) For the specific policies/roles that a user needs in order to create/manage an Elastic Beanstalk application, see the link here.
Application name
This will default to the directory name. Just go with that.
Python version
Next, the CLI should automagically detect that you are using Python and just ask for confirmation. Say yes. Then you need to select a platform version. Select Python 2.7.
SSH
Say yes to setting up SSH for your instances.
RSA Keypair
Next, you need to generate an RSA keypair, which will be added to your ~/.ssh folder. This keypair will also be uploaded to the EC2 public key for the region you specified in step one. This will allow you to SSH into your EC2 instance later in this tutorial.
eb create
Environment Name
You should use a similar naming convention to what Amazon suggest – e.g., application_name-env_name – especially when/if you start hosing multiple applications with AWS. I used – iod-test.
DNS CNAME prefix
When you deploy an app to Elastic Beanstalk you will automatically get a domain name like xxx.elasticbeanstalk.com. DNS CNAME prefix is what you want to be used in place of xxx. Just go with the default.
Installing packages
The first thing we need to do is install some packages so that our pip install command will complete successfully. To do this, let’s first create a file called .ebextensions/01_packages.config:
packages:
yum:
git: []
postgresql93-devel: []
EC2 instances run Amazon Linux, which is a Redhat flavor, so we can use yum to install the packages that we need. For now, we are just going to install two packages – git and the Postgres client.
To use the .config file option, let’s create a new file called /.ebextensions/02_python.config:
option_settings:
“aws:elasticbeanstalk:application:environment”:
DJANGO_SETTINGS_MODULE: “iotd.settings”
“PYTHONPATH”: “/opt/python/current/app/iotd:$PYTHONPATH”
“aws:elasticbeanstalk:container:python”:
WSGIPath: iotd/iotd/wsgi.py
NumProcesses: 3
NumThreads: 20
“aws:elasticbeanstalk:container:python:staticfiles”:
“/static/“: “www/static/“
What’s happening?
DJANGO_SETTINGS_MODULE: “iotd.settings” – adds the path to the settings module.
“PYTHONPATH”: “/opt/python/current/app/iotd:$PYTHONPATH” – updates our PYTHONPATH so Python can find the modules in our application. (Note that the use of the full path is necessary.)
WSGIPath: iotd/iotd/wsgi.py sets our WSGI Path.
NumProcesses: 3 and NumThreads: 20 – updates the number of processes and threads used to run our WSGI application.
“/static/“: “www/static/“ sets our static files path.
container_commands:
01_migrate:
command: “source /opt/python/run/venv/bin/activate && python iotd/manage.py migrate –noinput”
leader_only: true
02_createsu:
command: “source /opt/python/run/venv/bin/activate && python iotd/manage.py createsu”
leader_only: true
03_collectstatic:
command: “source /opt/python/run/venv/bin/activate && python iotd/manage.py collectstatic –noinput”
option_settings:
“aws:elasticbeanstalk:application:environment”:
DJANGO_SETTINGS_MODULE: “iotd.settings”
“PYTHONPATH”: “/opt/python/current/app/iotd:$PYTHONPATH”
“ALLOWED_HOSTS”: “.elasticbeanstalk.com”
“aws:elasticbeanstalk:container:python”:
WSGIPath: iotd/iotd/wsgi.py
NumProcesses: 3
NumThreads: 20
“aws:elasticbeanstalk:container:python:staticfiles”:
“/static/“: “www/static/“
We now need to ensure that the STATIC_ROOT is set correctly in the settings.py file:
STATIC_ROOT = os.path.join(BASE_DIR, “..”, “www”, “static”)
STATIC_URL = ‘/static/‘
django model null blank
django default is not null.
If we allow null value, add null=true option in model.
However, for CharField and TextField, we should not add it, because empty string (‘’) already represent null value.
In addition, set null=true means we also need to set blank=true.
Because in django, null controls the database setting; blank controls the form setting. So we need to set blank=true to allow the from field to be empty.
https://docs.djangoproject.com/en/1.8/ref/models/fields/#django.db.models.Field.null
angularjs post data to django server
Angularjs:
var my_app = angular.module(‘MyApp’).config(function($httpProvider) {
$httpProvider.defaults.headers.common[‘X-Requested-With’] = ‘XMLHttpRequest’;
$httpProvider.defaults.xsrfCookieName = ‘csrftoken’;
$httpProvider.defaults.xsrfHeaderName = ‘X-CSRFToken’;
});
$http.post(‘url’, {
data: $scope.data
}).success(function(data) {
console.log(data);
}).error(function(e) {
console.log(e);
});
Django:
from django.http import HttpResponseBadRequest
from django.http import JsonResponse
import json
def post(request):
if not request.is_ajax():
return HttpResponseBadRequest(‘Expected an XMLHttpRequest’)
in_data = json.loads(request.body.decode(‘utf-8’))
return JsonResponse({‘status’:’success’})
install postgres postgis in mac
mac pyenv install fail due to lib
zipimport.ZipImportError: can’t decompress data; zlib not available
CFLAGS="-I$(brew --prefix openssl)/include -I$(xcrun --show-sdk-path)/usr/include" \
LDFLAGS="-L$(brew --prefix openssl)/lib" \
pyenv install -v 3.5.0`</pre>
And actually it can be fixed when installed
<pre style="background-color: #f7f7f7; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; box-sizing: border-box; color: #333333; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 12px; line-height: 1.45; overflow: auto; padding: 16px; word-wrap: normal;">`xcode-select --install
then directly pyenv install xxx
Project Manager & Product Manager
身為一個新創團隊的 Project Manager 腦袋裡裝的常是,這樣的 Project 以哪種工具,會是有比較好的產出。通常以下這些會是 Project Manager 出現的工具:
AWS / Linode / React.js / Angular.js / Twitter Bootstrap / Sendgrid / New Relic / Asana / Redmine / Trello
而身為一個 Product Manager,最在乎的就是如何理解 user 的行為,而當你使用者不再是小貓兩三隻的時候,或許以下工具,會是你有用的助手
Google Analytics / Mailchimp / Uservoice / Google Web Master / Amplitude or Mixpanel / Custom.io / segment.io / facebook karma / Optimizely