0%

How to make a new post?

  • First step

    1
    hexo new "a new title"
  • Then locate the newly created file and edit it

  • Then try to see how it looks locally

    1
    hexo server
  • After editing it, publish it by

    1
    2
    3
    hexo clean
    hexo generate # this generate static files
    hexo deploy

    Give it a few minutes to show up. Be patient…

  • For RSS, you need a plug-in named hexo-generator-feed
    1
    npm install hexo-generator-feed --save

Convert game stick inputs to d-pad inputs

A game stick, or a joy stick, is one type of game controller that looks like this:

     __
    (  )
     ||
     ||
 ___|""|__.._
/____________\
\____________/~~~

I built a demo page to show how to map the inputs from the stick to up, down, left , right signals.

It refreshed my memory on vector math a little bit, which was fun.

Basically, a cross product can be utilized to determine which side one vector lies with respect to another vector.

References:
I pretty much learned how to draw a page like this from watching following Youtube channels.
Highly recommand:
Poth on Programming
Web dev simplified

I’m migrating my posts from my old site hosted in heroku.
Hexo is really a cool tool. And I can host everything statically in github. I knew this was doable but never got a chance to do it. Finally started migrating over this weekend (still working on it).
But it is actually pretty simple and I highly recommend using hexo for personal blogs.
Some tips setting it up.

More stuff coming.

Github.

Create a github repo and name it .github.io. Username has to be your github username.
Also you want to setup SSH in github.

NodeJS.

install Nodejs so that you can use npm

Hexo.

install command

1
npm install -g hexo-cli

create project

1
hexo init {project name}

compile your files into HTML:

1
hexo generate

try see it locally:

1
hexo serve

deploy to github

first need to update the _config.yml

1
2
3
4
5
6
7

# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
type: git
repo: {git repo ssh address}
branch: master

then git plugin for hexo

1
npm install hexo-deployer-git --save

now finally

1
hexo deploy

Example 1

from multiprocessing import Manager, Process

def timeout_query_by_func_name(params,settings,function_name):
m=Manager()
ns=m.Namespace()
ns.my_df=None
p= Process(target=function_name, args=(params,settings,ns))
p.start()
if ‘timeout’ in settings.keys():
timeout=int(settings[‘timeout’])
else:
timeout=600
p.join(timeout)
if p.is_alive():
p.terminate()
p.join()
raise Exception(‘Time out when calling ‘+function_name.name)
return ns.my_df

Example 2

def workon_finishing():
    ps=[]
    for product, run_id in product_runs.iteritems():
        p=Process(target=run_id_status_monitor, args=(product, run_id))
        p.start()
        ps.append(p)

print("Start monitoring..... this can take up to a few hours")
for p in ps:
    p.join()
print("Stopped monitoring. This run is closed.")
Mind the COMMA

If you see something like...

TypeError: 'somekindof' object is not iterable

just change the args=(something) to args=(something,)

About 'shared' objects, below trials are actually not recommended, especially for Process. It adds quite a lot overhead. Thread are fine with that dfs. Idk why but using list references are very addictive in Python.

from multiprocessing import Process, Manager
import pandas as pd
import threading

def f1(name_space):
name_space.df=pd.DataFrame({‘a’:[1,2],’b’:[3,4]})

def f2(name_space):
name_space.df=pd.DataFrame({‘a’:[1,4],’b’:[2,3]})

def f3(items,i):
items[i]=pd.DataFrame({‘c’:[2,5]})

if name==”main“:
m=Manager()
ns=m.Namespace()
ns_1=m.Namespace()
ns_2=m.Namespace()
ns_3=m.Namespace()

ns_1.df=None
ns_2.df=None
ns_3.df=None

ps=[]
p1= Process(target=f1, args=(ns_1,))
p1.start()
p2= Process(target=f2, args=(ns_2,))
p2.start()
p3= Process(target=f1, args=(ns_3,))
p3.start()
p4= Process(target=f2, args=(ns_3,))
p4.start()
dfs=[None]*9
p3 = Process(target=f3, args=(dfs,1,))
p3.start()
t1=threading.Thread(target=f3, args=(dfs,2,))
t1.start()
ts=[]
for i in [4,6,7]:
    t=threading.Thread(target=f3,args=(dfs,i,))
    t.start()
    ts.append(t)
p1.join()
p2.join()
p3.join()
p4.join()
t1.join()
for t in ts:
    t.join()
print(ns_1.df)
print(ns_2.df)
print(ns_3.df)
print(dfs[1])
print(dfs[2])
print(dfs[4])
print(dfs[6])
print(dfs[7])
</code></pre>
the outputs are
 
   a  b
0  1  3
1  2  4
   a  b
0  1  2
1  4  3
   a  b
0  1  2
1  4  3
None
   c
0  2
1  5
   c
0  2
1  5
   c
0  2
1  5
   c
0  2
1  5
But, since join(timeout) only works for Process and with the nice terminate() function, please use Manager in case you need TIMEOUT. That's the whole point.
1
from multiprocessing.managers import Man def timeout_query_by_func_name(params,settings,function_name): m=Manager() ns=m.Namespace() ns.my_df=None p= Process(target=function_name, args=(params,settings,ns)) p.start() if 'timeout' in settings.keys(): timeout=int(settings['timeout']) else: timeout=600 p.join(timeout) if p.is_alive(): p.terminate() p.join() raise Exception('Time out when calling '+function_name.__name__) return ns.my_df

see logs:
heroku logs –tail
ctrl c to quit

heroku create

need pipenv
pipenv –three
pipenv install (inside the app directory)
pipenv shell

Deploy:
git add .
git commit -m “Demo”
git push heroku master
heroku open

heroku domains:add www.yourwebsite.com

if changed name
https://stackoverflow.com/questions/7615807/renamed-heroku-app-from-website-now-its-not-found
git remote rm heroku
git remote add heroku git@heroku.com:yourappname.git
and…
1). open a terminal
2). Go to your_app_directory/.git/config
3). Once you open the config file then edit as follows:
Change
url = git@heroku.com:old_app_name.git
to
url = git@heroku.com:new_app_name.git

in the manage.py
change app.settings

Now, database
heroku addons

heroku config (to see the database_url)
DATABASE_URL: postgres://mememe:nonono@something.amazonaws.com:5432/dbdbdb

then change in the django settings

DATABASES = {
‘default’: {
‘ENGINE’: ‘django.db.backends.postgresql_psycopg2’,
‘NAME’: ‘dbdbdb’,
‘USER’: ‘mememe’,
‘PASSWORD’: ‘nonono’,
‘HOST’: ‘something.amazonaws.com’,
‘PORT’: ‘6543’,
}
# ‘default’: {
# ‘ENGINE’: ‘django.db.backends.sqlite3’,
# ‘NAME’: os.path.join(BASE_DIR, ‘db.sqlite3’),
# }
}

then do ‘python manage.py migrate’
this create the tables

export PATH=/Applications/Postgres.app/Contents/Versions/10/bin/:$PATH
THEN
heroku pg:psql

https://gist.github.com/sirodoht/f598d14e9644e2d3909629a41e3522ad