tag:blogger.com,1999:blog-1632720268124791392024-02-19T06:47:02.237-08:00Merc Studio Tech BlogAnonymoushttp://www.blogger.com/profile/17205122072563787162noreply@blogger.comBlogger372125tag:blogger.com,1999:blog-163272026812479139.post-17329158212658272352017-01-25T20:27:00.003-08:002017-01-25T20:33:38.559-08:00setting up automatic deployment via gitIf you wish to have automatic deployment with rails and thin, here is an example:<br />
<br />
1st, clone your repository on server to a path.<br />
Next, vi .git/hooks/post-merge<br />
add in your bash script to run after git is pull<br />
example:<br />
bash -lc /pathtoroot/deploy.sh<br />
<br />
chmod a+x .git/hooks/post-merge<br />
<br />
in your git repository, add a file called: <b>deploy.sh</b>, you may code any deployment command after git pull, example:<br />
RAILS_ENV=production<br />
cd /pathtoroot<br />
echo "deploy.sh: bundle install"<br />
bundle install<br />
echo "deploy.sh: rake db:migrate"<br />
bundle exec rake db:migrate<br />
echo "deploy.sh: rake assets:precompile"<br />
bundle exec rake assets:precompile<br />
echo "deploy.sh: restarting"<br />
bundle exec thin -C config/thin.yml restart<br />
bundle exec sidekiqctl stop tmp/sidekiq.pid 0<br />
bundle exec sidekiq -d -P tmp/sidekiq.pid -L log/sidekiq.log<br />
echo "deploy.sh: Done!"<br />
<br />
makesure you have chmod a+x deploy.sh and commit this file via git on your local machine.<br />
<br />
on server, add a cron job to automatically pull on a period basis:<br />
crontab -e<br />
---<br />
* * * * * bash -lc "cd /pathtoroot/ && git pull"<br />
* * * * * sleep 30 && bash -lc "cd /pathtoroot/ && git pull"<br />
---<br />
<br />
2nd command allows you to run git pull within 30seconds.<br />
<br />
Once git pull is successful, it will auto trigger post-merge and run your deploy.sh<br />
<br />
hope it helps :)<br />
<br />
<br />
<div>
<br /></div>
<br />
<br />Anonymoushttp://www.blogger.com/profile/17205122072563787162noreply@blogger.com0tag:blogger.com,1999:blog-163272026812479139.post-4242724920472268562016-05-05T07:29:00.002-07:002016-05-05T08:01:51.122-07:00beego bee tool migration error?beego default migration tool does not show any error,<br />
its very annoying.<br />
<br />
here is a fix, either<br />
go get github.com/u007/bee<br />
<br />
OR<br />
<br />
clone this repository instead,<br />
and goto $gopath<br />
cd github.com/u007/bee<br />
run:<br />
go build<br />
go install<br />
<br />
and now, rerun your bee migrateAnonymoushttp://www.blogger.com/profile/17205122072563787162noreply@blogger.com0tag:blogger.com,1999:blog-163272026812479139.post-9713890373774777662016-04-24T07:16:00.003-07:002016-04-24T07:19:37.882-07:00rails 5 hstore hashRails 5 now returns params as a class instance, no longer a hash.<br />
due to the requirement to have random hashs key based on user input,<br />
the only way to do this is to force this value by calling .to_unsafe_h<br />
<br />
example:<br />
res = params.require(:detail).permit(:name, :year)<br />
res[:specification] = params[: detail][:specification].to_unsafe_h<br />
<br />
but if you do know your hash key, call this instead:<br />
permit(:specification => { :keyname1, keyname2 }<br />
<br />
if you have any suggestion, please comment :)<br />
<br />
<a href="https://forum.upcase.com/t/rails-doesnt-recognize-a-request-as-patch/5115">https://forum.upcase.com/t/rails-doesnt-recognize-a-request-as-patch/5115</a><br />
<br />
<a href="http://eileencodes.com/posts/actioncontroller-parameters-now-returns-an-object-instead-of-a-hash/">http://eileencodes.com/posts/actioncontroller-parameters-now-returns-an-object-instead-of-a-hash/</a><br />
<br />Anonymoushttp://www.blogger.com/profile/17205122072563787162noreply@blogger.com0tag:blogger.com,1999:blog-163272026812479139.post-51459713043477572482016-04-12T20:42:00.001-07:002016-04-12T21:05:41.600-07:00speed up rails developmentOne of the main concern with rails development is the speed.<br />
its very slow indeed when your stack grows.<br />
<br />
I found several reasons for it to be slow:<br />
<br />
<ol>
<li><b>assets</b>, when debug is enabled, each individual js and css file will be loaded individually</li>
<li><b>navigation</b> menu with permission triggers query and outputting links to admin requires some loading time</li>
<li><b>crud</b> - list and read is rendered everytime even though record is not updated, this can save more time</li>
<li><b>sassc</b> - compiling and loading sass is very slow in ruby</li>
</ol>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgkuC_atBlQcEBfBE-naBCFlfqXIFnfDtdbswpcStnObWl9DFmxMrGFWH510fmY88GIcoA2Zvkzl5s-d4XHwnjGAuXV9ZEzR6UVff4gX_Xi2MWuPAtcNCSLO9LCqD77qzokOI4JP7d3Ikc/s1600/Screen+Shot+2016-04-13+at+11.21.36+AM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="324" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgkuC_atBlQcEBfBE-naBCFlfqXIFnfDtdbswpcStnObWl9DFmxMrGFWH510fmY88GIcoA2Zvkzl5s-d4XHwnjGAuXV9ZEzR6UVff4gX_Xi2MWuPAtcNCSLO9LCqD77qzokOI4JP7d3Ikc/s640/Screen+Shot+2016-04-13+at+11.21.36+AM.png" width="640" /></a></div>
<div>
<br /></div>
<h2>
1. Assets</h2>
<div>
If you aren't planning to debug any scripting or css, set</div>
<div>
config.assets.debug = false # set this to false if you dont plan to debug your css or js</div>
<div>
config.assets.digest = true # this recommended permanently to allow cache on browser</div>
<div>
<br /></div>
<br />
<h2>
2. Navigation menu</h2>
<div>
<div>
Navigation menu via cancancan gem requires some query to the database. Often this file is not changed frequently, its almost once setup, its forgotten. Therefore it make sense to cache this file based on user session. One way todo this is to cache this based on template name with prefix and current user id.</div>
</div>
<div>
<br /></div>
<div>
example:</div>
<div>
views/layout/admin/_nav.html.slim</div>
<div>
- cache("template_layout_admin_nav_#{current_user.id rescue 0}") do </div>
<div>
nav. ...</div>
<div>
... (more code here)</div>
<div>
<br /></div>
<div>
<h2>
3. List & read</h2>
<div>
Since most record will not be changed, it make sense to cache each individual view fragment for respective model to be cached. They call this russian doll caching. Rails cache is smart enough to update cache when model updated_at changes. This can be applied to both listing and show.</div>
</div>
<div>
<br /></div>
<div>
example listing template:</div>
<div>
<br /></div>
<div>
<div>
tbody</div>
<div>
- @rows.each do |row|</div>
<div>
- cache row do</div>
</div>
<div>
td = row.id</div>
<div>
td ...</div>
<div>
<br /></div>
<div>
example show template:</div>
<div>
<div>
- cache @record do</div>
<div>
.panel-body.resource.box.p-a</div>
<div>
.row</div>
<div>
.col-md-12</div>
</div>
<div>
= @record.id<br />
<br />
<h2>
4. Use sassc</h2>
<div>
Sass compilation on rails is slow. Recently, we have found an alternative for faster sass compilation. Make use of sassc, add this into Gemfile.<br />
gem 'sassc-rails', group: [:development, :test, :staging]<br />
<br />
It is not recommended to run assets precompile on production server. Its slow and takes a long time to update on server. One way to do this is to compile assets locally.<br />
<br />
Before every deployment, run this to update your assets. But because we do not wish to load static assets on our development, add this to config/environment/<b>development</b>.rb<br />
config.assets.prefix = '/<b>dev-assets</b>'<br />
<br />
in config/<b>application</b>.rb<br />
config.assets.<b>initialize_on_precompile</b> = <b>false </b># this ensure local assets precompile for production works without the need to connect to production database<br />
<br />
This configuration ensure all assets is delivered via <b>dev</b>-<b>assets</b> on local development, while production assets is generated into public/<b>assets </b>and<b> </b>retrieved<b> </b>via<b> /assets</b><br />
<br />
To compile assets for production, run this:<br />
export RAILS_ENV=production; bundle exec rake assets:precompile</div>
</div>
<div>
<br /></div>
<div>
If you have relative uri to your rails instance, call this:</div>
<div>
<div>
export RAILS_ENV=production; export <b>RAILS_RELATIVE_URL_ROOT</b>=<b>/shop</b>; bundle exec rake assets:precompile</div>
</div>
<div>
# where /shop = uri to your site</div>
<div>
<br /></div>
<div>
<h2>
To enable cache in development</h2>
<span style="font-weight: normal;">in config/environment/development.rb,</span></div>
<div>
<div>
config.<b>action_controller</b>.<b>perform_caching</b> = <b>true</b></div>
<div>
config.cache_store = :<b>file_store</b>, Rails.root.join('tmp', 'cache'), { size: 64.megabytes }</div>
<div>
# config.cache_store = :<b>memory_store</b>, { size: 64.megabytes }</div>
<div>
config.public_file_server.headers = {</div>
<div>
'Cache-Control' => 'public, max-age=172800'</div>
<div>
}</div>
</div>
<div>
<br /></div>
<div>
It is recommended to set cache memory_store, so that every time you wish to clear cache, simply restart the rails instance. But if you want to have it persistant on every time, use file_store cache.</div>
<div>
But if you ever change the template file in navigation, you will need to clear the cache directory</div>
<div>
rm -Rf tmp/cache/<b>#</b></div>
<div>
# = represent the cached folder (ls -lat to get the current directory name)</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br />
For further speed tuning, please follow the instruction below:<br />
<a href="https://www.nateberkopec.com/2015/08/05/rack-mini-profiler-the-secret-weapon.html">https://www.nateberkopec.com/2015/08/05/rack-mini-profiler-the-secret-weapon.html</a><br />
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
Anonymoushttp://www.blogger.com/profile/17205122072563787162noreply@blogger.com0tag:blogger.com,1999:blog-163272026812479139.post-55355505210650239712016-03-22T08:05:00.001-07:002016-03-22T08:12:02.764-07:00turbolinks 5 and ckeditorturbolinks 5 gives some pretty neat features.<br />
it no longer needs turbolinks-jquery.<br />
<br />
but in some way, it doesnt work properly due to cache within turbolinks.<br />
a work around this issue would be calling:<br />
<br />
#coffeescripts:<br />
jQuery(document).on('turbolinks:load', (e)-><br />
#do your initialize here<br />
if Turbolinks<br />
Turbolinks.Cache()<br />
)<br />
<br />
calling turbolinks cache helps to keep the rendered form intact.<br />
but for some reason, this doesn't work with ckeditor.<br />
<br />
the work around is to add this in the turbolinks:load function<br />
<br />
$('textarea.ckeditor').each(-><br />
if $(this).css('visibility') != 'hidden'<br />
# console.log(this)<br />
CKEDITOR.replace(this)<br />
)<br />
<br />
hope it helps :)<br />
<br />
<br />Anonymoushttp://www.blogger.com/profile/17205122072563787162noreply@blogger.com0tag:blogger.com,1999:blog-163272026812479139.post-69711889221822745272016-02-18T10:01:00.001-08:002016-02-18T10:02:53.577-08:00rails local assets precompileif you have spring, you may not run bin/rake or bin/rails assets:precompile.<br />
<br />
here is a way todo it right<br />
<br />
<div class="p1">
<span class="s1">RAILS_ENV=production bundle exec rake assets:precompile</span></div>
<div class="p1">
<span class="s1"><br /></span></div>
<div class="p1">
<span class="s1">ensure that you have (config/<b>application</b>.rb) set</span></div>
<div class="p1">
<span class="s1">config.assets.initialize_on_precompile = false</span></div>
<div class="p1">
<span class="s1"><br /></span></div>
<div class="p1">
and for development:</div>
<div class="p1">
config/environment/<b>development</b>.rb</div>
<div class="p1">
config.assets.prefix = '/dev-assets' # to avoid assets precompile everytime u change a css or js</div>
<div class="p1">
<br /></div>
<div class="p1">
<br /></div>
<div class="p1">
<br /></div>
<div class="p1">
<br /></div>
Anonymoushttp://www.blogger.com/profile/17205122072563787162noreply@blogger.com0tag:blogger.com,1999:blog-163272026812479139.post-5031083020409782882016-01-13T10:50:00.003-08:002016-01-13T10:52:05.206-08:00gem install mysql -v 0.3ive issues with rails 4.1 that it does not play well with mysql2 v 0.4 .<br />
im forced to use mysql2 v 0.3.20<br />
<br />
when i ran gem install mysql -v 0.3.20<br />
i came to this error:<br />
<br />
<div class="p1">
<span class="s1"><b>errmsg.h is missing</b></span></div>
<div class="p1">
<span class="s1"><br /></span></div>
<div class="p1">
<span class="s1">ive already had mysql-dev installed.</span></div>
<div class="p1">
<span class="s1">after searching around, i found the issue.</span></div>
<div class="p1">
cpanel mysql-config is still using mysql 5 dev library.<br />
when i ran which mysql-config, and mysql-config, ive gotten cpanel 3rd party bin with v5.</div>
<div class="p1">
<br /></div>
<br />
so i renamed cpanel own mysql-config, and relink the correct mysql-config to cpanel/bin<br />
<div class="p1">
<span class="s1">mv /usr/local/cpanel/3rdparty/bin/<b>mysql_config</b> /usr/local/cpanel/3rdparty/bin/<b>mysql_config5</b></span></div>
<br />
<div class="p1">
<span class="s1">ln -s /usr/bin/mysql_config /usr/local/cpanel/3rdparty/bin/mysql_config</span></div>
<div class="p1">
<span class="s1"><br /></span></div>
<div class="p1">
<span class="s1">reran gem install and bundle, and it works great now!</span></div>
<div class="p1">
<span class="s1"><br /></span></div>
<div class="p1">
<span class="s1"><br /></span></div>
Anonymoushttp://www.blogger.com/profile/17205122072563787162noreply@blogger.com0tag:blogger.com,1999:blog-163272026812479139.post-24434956323454697472016-01-10T07:56:00.002-08:002016-01-10T07:58:41.317-08:00rails admin date time input formatafter upgrading to rails admin 0.8.1,<br />
took me few hours trying to figure why all my datetime input fail to work.<br />
<br />
it turned out that rails admin have forced their datetime input format based on<br />
en.time.formats.long<br />
this can be set in en.yml<br />
<br />
otherwise, you may set the datetime by declaring in the configuration, etc:<br />
<div class="p1">
<span class="s1">field :created_at do</span></div>
<div class="p1">
<span class="s1"> date_format do</span></div>
<div class="p1">
<span class="s1"> :<b>short</b></span></div>
<div class="p1">
<span class="s1"> end</span></div>
<br />
<div class="p1">
<span class="s1">end</span></div>
<div class="p1">
<span class="s1"><br /></span></div>
<br />
for more formats:<br />
<a href="http://apidock.com/ruby/DateTime/strftime" target="_blank">http://apidock.com/ruby/DateTime/strftime</a><br />
<br />
<br />Anonymoushttp://www.blogger.com/profile/17205122072563787162noreply@blogger.com0tag:blogger.com,1999:blog-163272026812479139.post-48715691855607313712016-01-04T00:57:00.001-08:002016-01-04T05:28:26.718-08:00capistrano is slow, alternative: blazingcapistrano seems to be quite slow to deploy.
it works great for production, as it export entire git into independent directory and relink directory from shared directory.
<br />
<br />
In some of my smaller projects, i would prefer to maintain only 1 folder, and do a git hard reset and push the update directly from my local git.<br />
my work around is to use <b>blazing</b>. since blazing 0.5, <b>recipes</b> is <b>no</b> longer supported.<br />
blazing by default works great! but until you realize you are using <b>spring</b>, and <b>passenger</b><br />
<br />
ive customize blazing with spring generated bin removed from bin.<br />
<br />
<a href="https://github.com/u007/blazing" target="_blank">https://github.com/u007/blazing</a><br />
<br />
to deploy:<br />
<ol>
<li>create to $HOME/rails/shared</li>
<li>upload shared/config/application.yml (for figaro)</li>
<li>mkdir shared/log</li>
<li>mkdir shared/public/uploads</li>
<li>mkdir shared/public/system</li>
<li>mkdir shared/tmp</li>
<li>mkdir shared/vendor/bundle</li>
</ol>
<br />
next, in your project,<br />
<div>
<ol>
<li>blazing init</li>
<li>edit config/blazing.rb<br />rake :"server:deploy"</li>
<li>copy this file to lib/tasks/<br /><a href="http://pastebin.com/13cTyvGg">http://pastebin.com/13cTyvGg</a> #if you use mod passenger</li>
<li>blazing setup <b>production</b><br /># this will deploy git after deploy scripts on server</li>
<li>blazing update <b>production</b> # to update later if changed blazing config</li>
</ol>
<div style="font-weight: bold;">
<b><br /></b></div>
to <b>deploy</b> updates, simply:</div>
<div>
<ol>
<li>git push <b>production</b> <b>master</b> # remote: production, local branch: <b>master</b></li>
</ol>
<b><br /></b></div>
Anonymoushttp://www.blogger.com/profile/17205122072563787162noreply@blogger.com0tag:blogger.com,1999:blog-163272026812479139.post-17751073337817060662015-12-27T22:16:00.001-08:002015-12-27T22:35:16.953-08:00undefined method `register_preprocessor' for nil:NilClass seems to occur on sprocket-rails v3.0
sprockets-rails (2.3.3) works great!
sprocketrails 2.3.3 + sprockets (3.5.2)
it was due to less-rails
https://github.com/rails/rails/issues/22647
Anonymoushttp://www.blogger.com/profile/17205122072563787162noreply@blogger.com0tag:blogger.com,1999:blog-163272026812479139.post-15263261618847538682015-12-03T06:20:00.003-08:002015-12-03T06:20:58.136-08:00android rotating image based on Uri / File<iframe src="http://pastebin.com/embed_iframe.php?i=W9dYVSKz" style="border: none; height: 650px; width: 100%;"></iframe>Anonymoushttp://www.blogger.com/profile/17205122072563787162noreply@blogger.com0tag:blogger.com,1999:blog-163272026812479139.post-82580730775942695122015-11-25T09:41:00.001-08:002015-11-25T09:41:03.328-08:00dbflow raw queryAs example:<pre style="background-color: white; font-family: Menlo; font-size: 12pt;"><span style="color: navy; font-weight: bold;">
</span></pre>
<pre style="background-color: white; font-family: Menlo; font-size: 12pt;"><span style="color: navy; font-weight: bold;">class Abc {</span></pre>
<pre style="background-color: white; font-family: Menlo; font-size: 12pt;"><span style="color: navy; font-weight: bold;">public static </span>String get_latest_updated_at(Class model, String where, Object... args) {
ColumnAlias[] alias = <span style="color: navy; font-weight: bold;">new </span>ColumnAlias[<span style="color: blue;">1</span>];
alias[<span style="color: blue;">0</span>] = ColumnAlias.<span style="font-style: italic;">columnRaw</span>(<span style="color: green; font-weight: bold;">"max(updated_at) as updated_at"</span>);
String query = <span style="color: green; font-weight: bold;">"select max(updated_at) as updated_at from "</span>+FlowManager.<span style="font-style: italic;">getTableName</span>(model);
Cursor cursor = FlowManager.<span style="font-style: italic;">getDatabaseForTable</span>(model).getWritableDatabase().rawQuery(query, <span style="color: navy; font-weight: bold;">null</span>);</pre>
<pre style="background-color: white; font-family: Menlo; font-size: 12pt;"><span style="color: navy; font-weight: bold;"> if</span>(cursor.getCount() > <span style="color: blue;">1</span>)
<span style="color: navy; font-weight: bold;">return </span><span style="color: green; font-weight: bold;">""</span>;
cursor.moveToFirst();
<span style="color: navy; font-weight: bold;">return </span>cursor.getString(cursor.getColumnIndex(<span style="color: green; font-weight: bold;">"updated_at"</span>));
}</pre>
<pre style="background-color: white; font-family: Menlo; font-size: 12pt;">
</pre>
<pre style="background-color: white; font-family: Menlo; font-size: 12pt;">
</pre>
<pre style="background-color: white; font-family: Menlo; font-size: 12pt;">}</pre>
<pre style="background-color: white; font-family: Menlo; font-size: 12pt;">
</pre>
<pre style="background-color: white; font-family: Menlo; font-size: 12pt;">calling example:</pre>
<pre style="background-color: white; font-family: Menlo; font-size: 12pt;"><pre style="font-family: Menlo; font-size: 12pt;"><span style="font-style: italic;">Abc.get_latest_updated_at</span>(Address.<span style="color: navy; font-weight: bold;">class</span>, <span style="color: green; font-weight: bold;">""</span>)</pre>
<pre style="font-family: Menlo; font-size: 12pt;">
</pre>
<pre style="font-family: Menlo; font-size: 12pt;">//where by Address is model extending BaseModel</pre>
<pre style="font-family: Menlo; font-size: 12pt;">
</pre>
</pre>
Anonymoushttp://www.blogger.com/profile/17205122072563787162noreply@blogger.com0tag:blogger.com,1999:blog-163272026812479139.post-25515606581983420692015-11-23T03:10:00.000-08:002015-11-23T03:10:02.323-08:00undefined local variable or method `try_spree_current_user'If you create your custom spree controller,<br />
<br />
beware that you will need to add in some spree controller helper to make the magic works<br />
<br />
include Spree::Core::ControllerHelpers::Auth<br />
include Spree::Core::ControllerHelpers::Store<br />
include Spree::Core::ControllerHelpers::Order<br />
<br />
or<br />
<br />
you may extends from <b>Spree</b>::<b>BaseController</b><br />
<br />
<br />
<br />
<br />
<br />Anonymoushttp://www.blogger.com/profile/17205122072563787162noreply@blogger.com0tag:blogger.com,1999:blog-163272026812479139.post-57702496578245723642015-10-23T10:06:00.005-07:002015-10-23T10:06:55.515-07:00authorize! for update<div class="p1">
<span class="s1">just realize calling model.update after authorize! is wrong!</span></div>
<br />
<div class="p1">
<span class="s1">the right way is to run an authorize!, then model.assign_attributes, then rerun authorize! again, </span></div>
<div class="p1">
<span class="s1">and finally model.save</span></div>
Anonymoushttp://www.blogger.com/profile/17205122072563787162noreply@blogger.com0tag:blogger.com,1999:blog-163272026812479139.post-76122600465913213342015-10-20T10:36:00.002-07:002015-10-20T10:38:02.200-07:00running rvm based cron jobrvm is requires a bash login to work.<br />
in order to execute cron jobs, run this:<br />
<br />
*/5 * * * * 'sh /home/myuser/versions/current/runme.sh'<br />
<br />
create a shell file,<br />
change working directory to rails root,<br />
and run the required job, such as delayed_job once and exit<br />
<br />
vi /home/myuser/versions/current/runme.sh<br />
cd /home/myuser/versions/current<br />
/bin/bash -l -c 'RAILS_ENV=production bundle exec rake jobs:workoff'<br />
<div>
<br />
<br /></div>
<div>
<br /></div>
Anonymoushttp://www.blogger.com/profile/17205122072563787162noreply@blogger.com0tag:blogger.com,1999:blog-163272026812479139.post-51574831070949662512015-10-01T05:23:00.002-07:002015-10-02T08:36:41.147-07:00speeding up vagrant and virtualbox synced folder on mac and windows<br />
On <b>MAC</b>:<br />
first, use nfs for sync folder,<br />
<br />
in Vagrantfile:<br />
web.vm.synced_folder "/private/var/www", "/var/www", type: "<b>nfs</b>", mount_options: ['rw', 'vers=3', 'tcp', 'fsc', '<b>actimeo=2</b>']<br />
<br />
<b>actimeo=2</b> # increases speed of file sync<br />
<br />
then do a:<b> </b><br />
<b>vagrant reload</b><br />
<b><br /></b>
<b><br /></b><br />
<b><br /></b>
On <b>Windows:</b><br />
web.vm.synced_folder "c:/wamp/www", "/var/www", type: "<b>smb</b>"<br />
<br />
Notes: nfs on windows is not fully compatible. On linux guest machine, it does not allow file locking. This isn't good enough with rails, especially. Smb is an good option with file locking support, and fast response time. But this requires running <b>command</b> <b>prompt</b> as <b>administrator</b> to start smb command.<br />
<br />
<br />
Hope it helps ;)<br />
<br />Anonymoushttp://www.blogger.com/profile/17205122072563787162noreply@blogger.com0tag:blogger.com,1999:blog-163272026812479139.post-67062121328896291552015-08-28T07:56:00.001-07:002015-08-28T09:52:44.944-07:00installing volley for androidLatest volley is available in maven repository,<br />
therefore, you do not need to compile volley from source code.<br />
goto Build > Library and dependencies > dependencies<br />
click + add, search for volley<br />
com.mcxiaoke.volley:library-aar:1.0.1<br />
<br />
<br />
<b>If you insists:</b><br />
---old stuff---<br />
Follow instruction here:<br />
http://www.androidhive.info/2014/05/android-working-with-volley-library-1/<br />
<br />
but first, makesure you have setup your environment and paths:<br />
<br />
<div class="p1">
<span class="s1">PATH=$PATH:/<b>path-to-android-sdks</b>/platform-tools:</span><b>/path-to-android-sdks/</b>tools:"/Applications/Android Studio.app/Contents/gradle/gradle-<b>2.4</b>/bin"</div>
<br />
<div class="p1">
<span class="s1">export ANDROID_HOME=</span>/path-to-android-sdks</div>
<div class="p1">
<br /></div>
<div class="p1">
(Please change the path-to-android-sdks and gradle version accordingly)</div>
<div class="p1">
<br /></div>
<div class="p1">
for windows, you may use SET instead of export.</div>
<div class="p1">
example: set PATH=<span style="background-color: white; color: #222222; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 15px; line-height: 19.5px;">%PATH%;...</span></div>
<div class="p1">
<span style="background-color: white; color: #222222; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 15px; line-height: 19.5px;"><br /></span></div>
<div class="p1">
And,<br />
<br />
instead of using ant to build, use `gradle build`.<br />
didnt work for me, i tried to use android studio to open the project, and did not manage to get it compiled...<br />
<br /></div>
Anonymoushttp://www.blogger.com/profile/17205122072563787162noreply@blogger.com0tag:blogger.com,1999:blog-163272026812479139.post-62108216944530177652015-07-30T23:08:00.000-07:002015-07-30T23:31:40.110-07:00connecting to sql server with railssql server / sql express is by default cannot be connected by a fixed port<br />
to login to sql server, first, assign a password for sa user,<br />
or any user, and map the database to the user.<br />
you may use db_owner for default role mapping.<br />
<br />
then open <span style="background-color: white; color: #333333; font-family: Cambria; font-size: 14.6666666666667px; font-weight: bold; vertical-align: baseline; white-space: pre-wrap;">sql</span><span style="background-color: white; color: #333333; font-family: Cambria; font-size: 14.6666666666667px; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="background-color: white; color: #333333; font-family: Cambria; font-size: 14.6666666666667px; font-weight: bold; vertical-align: baseline; white-space: pre-wrap;">configuration manager</span><br />
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">select </span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">sql server netwrok configuration</span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> > Protocols for </span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">localhost / express / your instance name</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">select </span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">TCP/IP </span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">scroll to bottom, and set:</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 14.6666666666667px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">all ports</span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 14.6666666666667px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">:</span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 14.6666666666667px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><b>1433</b></span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">dynamic port: (empty, not even a zero)</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">then goto control panel > </span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">services</span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> > </span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">sql server</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">restart</span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">service</span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">,</span></div>
<span style="font-family: Arial; font-size: 14.6666666666667px; vertical-align: baseline; white-space: pre-wrap;">enable </span><span style="font-family: Arial; font-size: 14.6666666666667px; font-weight: bold; vertical-align: baseline; white-space: pre-wrap;">sql browser</span><span style="font-family: Arial; font-size: 14.6666666666667px; vertical-align: baseline; white-space: pre-wrap;"> (auto start delayed) and start service</span><br />
<span style="font-family: Arial; font-size: 14.6666666666667px; vertical-align: baseline; white-space: pre-wrap;"><br /></span>
<span style="font-family: Arial; font-size: 14.6666666666667px; vertical-align: baseline; white-space: pre-wrap;">this shall help to make it work with rails or tiny_tds</span>Anonymoushttp://www.blogger.com/profile/17205122072563787162noreply@blogger.com0tag:blogger.com,1999:blog-163272026812479139.post-75038699800756946052015-07-20T01:11:00.001-07:002015-07-20T01:11:31.045-07:00mariadb 10.0 upgrade from 5.5Upgrading to Mariadb10 seems to fail on my ubuntu 14 virtualbox.<br />
What i did was restart the instance,<br />
followed instruction from:<br />
<a href="https://mariadb.com/kb/en/mariadb/upgrading-from-mariadb-55-to-mariadb-100/" target="_blank">https://mariadb.com/kb/en/mariadb/upgrading-from-mariadb-55-to-mariadb-100/</a><br />
<br />
and prompt to replace my my.inf configuration with maintainer configuration.<br />
but it still failed.<br />
tail -n 200 /var/log/syslog turn out that it was unable to bind at 127.0.0.1.<br />
<br />
so i vi /etc/mysql/my.inf<br />
change the binding address to 0.0.0.0<br />
<br />
and it works :)<br />
<br />
<br />Anonymoushttp://www.blogger.com/profile/17205122072563787162noreply@blogger.com0tag:blogger.com,1999:blog-163272026812479139.post-33609520766438811672015-07-07T10:01:00.003-07:002015-07-20T01:14:02.212-07:00exim smarthost matching null or empty string via wildlsearchokay, it took me a long time to finally figure how to match possible null / empty string<br />
due to nature that sender_address_domain may be empty if its a bounce mail,<br />
delimiting it in a string did not work, turn out ive to just create a blank <b>{}</b><br />
<br />
<div class="p1">
client_send = : ${extract{auth_name}{${lookup{${if eq{$sender_address_domain}{}{'default'}{$sender_address_domain}}}nwildlsearch{/etc/smart}{$value}fail}}} : ${extract{auth_pass}{${lookup{${if eq{$sender_address_domain}{}{'default'}{$sender_address_domain}}}nwildlsearch{/etc/smart}{$value}fail}}}</div>
<div class="p2">
<span class="s1"></span><br /></div>
<div class="p1">
<span class="s1">with this, it matches in /etc/smart:</span></div>
<br />
<div class="p1">
<span class="s1">default: auth_name=... auth_pass=...</span><br />
<span class="s1"><br /></span>
<span class="s1"><br /></span>
<span class="s1">notice the {} empty without any string inside</span><br />
<span class="s1"><br /></span></div>
<div class="p1">
<span class="s1"><br /></span></div>
<div class="p1">
other complaints:<br />
- for some weird reason, strlen function wont work in section: auth...<br />
<br />
<br /></div>
Anonymoushttp://www.blogger.com/profile/17205122072563787162noreply@blogger.com0tag:blogger.com,1999:blog-163272026812479139.post-38051702907055580352015-05-25T07:46:00.003-07:002015-05-25T07:46:34.546-07:00executing apm with atom on windowsIf you have installed atom via chocolatey,<br />
the default path to apm for atom is located in<br />
<br />
C:\Users\yourname\AppData\Local\atom\app-0.201.0\resources\app\apm\bin<br />
<br />
<br />Anonymoushttp://www.blogger.com/profile/17205122072563787162noreply@blogger.com0tag:blogger.com,1999:blog-163272026812479139.post-24600611448263411302015-05-21T08:56:00.001-07:002015-05-21T08:58:02.888-07:00deploying to production via capistrano with passenger and sub uridue to digested assets requirement in production environment,<br />
the url of images cannot be use in relative to path to css file.<br />
<br />
example normal assets:<br />
/assets/frontend/all.css<br />
<br />
example of digested assets<br />
<br />
/assets/all.XXX.css<br />
<br />
due to this, the only way to accurately point to images in css is to add relative path to the url.<br />
one way todo it is to use ENV['RAILS_RELATIVE_URL_ROOT'],<br />
first, you will need to change .css file to .css.erb.<br />
and add in <%=ENV['RAILS_RELATIVE_URL_ROOT']%> to the url path.<br />
example: background-image: url('<%=ENV['RAILS_RELATIVE_URL_ROOT']%>/img/logo.png');<br />
<br />
but since we are precompiling via capistrano, it is a must to add this environment into deploy/production.rb<br />
example:<br />
set :bundle_flags, '--deployment' # set this to ensure traces of assets compilation can be shown via --trace<br />
set :default_env, {<br />
'RAILS_RELATIVE_URL_ROOT' => '/shop'<br />
}<br />
<br />
and then run:<br />
cap production deploy --trace<br />
<div>
<br />
took me hours to try to figure all the issues in place to resolve this.<br />
hope it helps you :)<br />
<br /></div>
Anonymoushttp://www.blogger.com/profile/17205122072563787162noreply@blogger.com0tag:blogger.com,1999:blog-163272026812479139.post-2766135622416006192015-05-13T18:44:00.000-07:002015-05-13T18:46:47.206-07:00apache with mod passenger with rails in sub uri<iframe src="http://pastebin.com/embed_iframe.php?i=TBSH6sbw" style="border: none; width: 100%;height: 200px;"></iframe>Anonymoushttp://www.blogger.com/profile/17205122072563787162noreply@blogger.com0tag:blogger.com,1999:blog-163272026812479139.post-77483793911806763662015-04-30T01:13:00.001-07:002015-05-29T00:33:06.693-07:00iis 7 and railsafter struggling to get things running,<br />
i finally found my best solution.<br />
<br />
<h3>
HttpPlatformHandler</h3>
If you are running iis 8, just use httpplatformhandler, it save you a lot of time. but you will need to get webmatrix running. but this is not supported on iis 7/7.5, a bummer :(<br />
<br />
<h3>
WebMatrix</h3>
so moving on to try microsoft web platform.<br />
<a href="https://www.microsoft.com/web/webmatrix">https://www.microsoft.com/web/webmatrix</a><br />
<br />
also several issues,<br />
webmatrix does not play well with <b>proxy</b>, ke-damn!<br />
<br />
Some odd / weird results when trying to install webmatrix,<br />
first, it requires iis express, and ive no idea why do it need it.<br />
but after running install and it failed, we are still able to open the webmatrix installer options.<br />
Just ignore the webmatrix installation issue.<br />
<br />
<h4>
webmatrix and proxy?</h4>
setting http proxy in environment does not help in one of my client case,<br />
you might want to consider setting up this:<br />
http://ntlmaps.sourceforge.net/ - works like a charm for me :)<br />
<br />
Okay, <b>please</b> please please <b>do not install helicon</b> method. Their ruby and rails are <b>outdated</b>!<br />
This will save you the hassle from installing old ruby 1.8 and 1.9 on your machines. And this may conflict with railsinstaller ruby.<br />
<br />
So, what now? how do we run rails on /rails uri?<br />
Yes, install Application Request Routing (ARR).<br />
Inside webmatrix, search for arr, install it :)<br />
After install, restart your iis manager (not refreshed if you have it opened while installing).<br />
<br />
Okay, unless you want to setup <b>entire</b> host to proxy to another port, dont setup ARR on root level.<br />
<br />
In my case, ive setup uri "/<b>rails</b>" to proxy over to my own rails instance.<br />
Todo so, create a application "<b>rails</b>" under Default sites.<br />
Then click into rails, and click on "Rewrite rules".<br />
Then "Add rule" > "Reverse proxy"<br />
Key in "127.0.0.1:3000" for server name,<br />
After adding, double click on the rules, and ensure that you have similar configuration alike below. Notice the {R:1} appended as suffix of the rewrite url.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgm_0km5ISo4ZMNtfa-SXwn0xYPOZjXZ1G-TpH8YnpsiC4fWH1b_Q48I4cIHKqjUijcOTTHbf4WaYfHSGJOTTvYeNhP1K-r0yYuzysIkNR_DcUbiHmDHNuHnOhSGBEo6-jjGuJQ9Ccdqgg/s1600/Screen+Shot+2015-04-30+at+4.08.35+PM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="523" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgm_0km5ISo4ZMNtfa-SXwn0xYPOZjXZ1G-TpH8YnpsiC4fWH1b_Q48I4cIHKqjUijcOTTHbf4WaYfHSGJOTTvYeNhP1K-r0yYuzysIkNR_DcUbiHmDHNuHnOhSGBEo6-jjGuJQ9Ccdqgg/s1600/Screen+Shot+2015-04-30+at+4.08.35+PM.png" width="640" /></a></div>
<br />
<h3>
Setting up Rails + Ruby</h3>
to setup ruby, goto <a href="http://railsinstaller.org/en" target="_blank">http://railsinstaller.org/en</a> (thank god engine yard started something for us).<br />
makesure to install with devkits and git and ssh.<br />
it makes life much easier.<br />
It will install to c:\RailsInstaller<br />
all the paths should have been set for you, thank god :)<br />
<br />
Then next, you might realize your gem install throws sslv3 certificate error with rubygems.org, another bummer. It turn out as of today 30th april 2015, certificate has been renewed on rubygems but it wasnt updated to the trusted repository of gems.<br />
Follow here:<br />
<a href="https://gist.github.com/luislavena/f064211759ee0f806c88">https://gist.github.com/luislavena/f064211759ee0f806c88</a><br />
<br />
Since im using 2.1.5, ive followed to 2.0.15 instruction (not sure why the 2.0).<br />
<a href="https://github.com/rubygems/rubygems/releases/tag/v2.0.15">https://github.com/rubygems/rubygems/releases/tag/v2.0.15</a><br />
<br />
Download the .gem, and runs:<br />
gem install --local <strong style="background-color: white; box-sizing: border-box; color: #4183c4; font-family: Helvetica, arial, nimbussansl, liberationsans, freesans, clean, sans-serif, 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 14px; line-height: 19.6000003814697px; text-decoration: none;"><a href="https://github.com/rubygems/rubygems/releases/download/v2.0.15/rubygems-update-2.0.15.gem" rel="nofollow" style="background-color: white; box-sizing: border-box; color: #4183c4; font-family: Helvetica, arial, nimbussansl, liberationsans, freesans, clean, sans-serif, 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 14px; line-height: 19.6000003814697px; text-decoration: none;">rubygems-update-2.0.15.gem</a></strong><br />
update_rubygems --no-ri --no-rdoc<br />
<br />
you may run:<br />
gem update (to test if it works)<br />
<br />
You will realize latest rails is already installed by railsinstaller.<br />
Create a new app to try<br />
c:\Sites\rails new app1<br />
<br />
then create a startup file (this is using webrick, best to replace using either puma or thin)<br />
@echo off<br />
set RAILS_ENV=production<br />
set RAILS_RELATIVE_URL_ROOT=/<b>rails</b><br />
set SECRET_KEY_BASE=yoursecretkeyshere<br />
rails s<br />
<br />
and edit config.ru<br />
and change `run Rails.application` to:<br />
---------<br />
map "/rails" do<br />
run Rails.application<br />
end<br />
<br />
map "/" do<br />
run Rails.application<br />
end<br />
---------<br />
<br />
Notice the uri rails is used to indicated a uri so that all proxy over from iis can be used with this uri.<br />
<br />
<h3>
Installing Mysql2 gem</h3>
ensure your mysql2 gem is 0.3.18 or later<br />
<br />
goto:<br />
https://dev.mysql.com/downloads/connector/c/<br />
install the connector of your platform and 32/64bits (install the installer if you want to use path below)<br />
<br />
next, run:<br />
path to connector: C:\Program Files\MySQL\MySQL Connector C #version<br />
example: <b>v6.1</b><br />
gem install mysql2 --platform=ruby -- '--with-mysql-dir="C:\Program Files\MySQL\MySQL Connector C 6.1"'<br />
<br />
<div>
<h3>
Gems requirements on windows</h3>
Due to bugs and issues on windows, these are the min require versions of gem if you need to use them on windows:<br />
<br />
gem 'eventmachine', '>=1.0.7'<br />
gem 'bcrypt', '>= 3.1.10'<br />
gem 'mysql2', '>=0.3.18'<br />
<br />
<br />
<br />
<br /></div>
<div>
<br /></div>
Anonymoushttp://www.blogger.com/profile/17205122072563787162noreply@blogger.com0tag:blogger.com,1999:blog-163272026812479139.post-23899185533540650432015-04-16T04:46:00.001-07:002015-04-16T04:46:26.493-07:00solr and pint solr 5 no longer support p prefixed fieldtype,<br />
therefore:<br />
pint, pstring, pdate, etc... no longer supported.<br />
<br />Anonymoushttp://www.blogger.com/profile/17205122072563787162noreply@blogger.com0