Skip to content

Instantly share code, notes, and snippets.

# in Vim
:args ~/src/myproject/**/*.ttl | argdo execute "normal gg=G" | update
@goooooouwa
goooooouwa / example usage of optional type.swift
Last active August 29, 2015 14:05
example usage of optional type in swift
var exampleDictionary = ["foo":1,"bar":2]
// an optional type means its value can either be some certain type or nothing at all( nil)
var optionalTypeVariable: Int? = exampleDictionary["someUncertainValue"]
// calling optionalTypeVariable will either return an integer or a nil, so you should normally check it’s value before actually using it
if optionalTypeVariable == nil {
println("The value of optionalTypeVariable is nil")
} else {
// calling optionalTypeVariable! will always return an integer, if optionalTypeVariable is in fact nil, then an assertion will be triggered.
@goooooouwa
goooooouwa / where condition syntax for join table example.rb
Created August 19, 2014 07:16
where condition syntax for join table example
# syntax: ModelName.joins(:association_name).where({joining_table_name: {column_name:"column value"}})
ContactField.joins(:contact_field_type).where({constr_base_contact_field_types: {name:"Email"}})
@goooooouwa
goooooouwa / show or hide line number.vim
Created September 4, 2014 03:09
command to show/hide line number in vim
# in normal mode
con
curl -i -F name=test -F filedata=@localfile.jpg http://example.org/upload
@goooooouwa
goooooouwa / remove_trailing_whitespaces.rb
Last active August 29, 2015 14:08
remove trailing whitespaces. works for strings like "Window Furnishings " and "Bollards ".
ConstrBase::Trade.find_each do |trade|
if matches = /^((\S+\s+)+(\S*))\s*$/.match(trade.name)
trade.name = matches[1]
trade.save
end
end
@goooooouwa
goooooouwa / 7_items_in_a_12_grid_row.html
Created December 9, 2014 03:45
how to confortably put 7 items in a 12 grid row
<div class="row">
<div class="col-xs-11">
<div class="row">
<div class="col-xs-2">
</div>
<div class="col-xs-2">
</div>
<div class="col-xs-2">
</div>
<div class="col-xs-2">

小窍门: 如何在Keynote中插入代码且不丢失样式?

##步骤:

  1. 安装MacVim并用它打开你的源代码
  2. 选择菜单栏中_Syntax_下的_Convert to HTML_
  3. 选中新创建的包含HTML的buffer,然后选择_Files » Save_
  4. 在Safari中打开这个HTML文件( 它与你的源代码在同一个目录下)。你会看见一份完美复制了源代码在MacVim中样式的网页。
  5. 接下来只需选中Safari中显示的代码并拖拽到Keynote的页面中即可。下面附上一份源代码转换后的HTML样例,你可以将它保存文件后用浏览器打开,便可知道它看起来如何。
@goooooouwa
goooooouwa / post_to_get_search_result_in_xls.sh
Created December 31, 2014 15:15
minimal working version of post request to get search result in xls
curl -XPOST -H "Content-Type: application/json" -d '{"document": {}}' http://127.0.0.1:3000/documents/search.xls -v

Rule of thumb: Rails by default prints datetime in ISO8601 format in %Y-%m-%d %H:%M:%S +offset style, e.g. 2014-12-18 13:00:00 +1000 and encode datetime in JSON as standard_son_format, e.g. 2005-02-01T05:15:10.000-10:00

Angular formats datetime in timezone of the browser if timezone option of date filter is not specified.

Browsers format datetime string based on local date format settings. But browsers only support datetime-local picker.

With Rails datetime_local_field, the timezone is ignored, it outputs something like this ``.