Skip to content

Instantly share code, notes, and snippets.

View ozgun's full-sized avatar

Ozgun Koyun ozgun

View GitHub Profile
@ozgun
ozgun / mongo_document_size.js
Created December 4, 2012 16:43
mongo document size
// mongo document size
Object.bsonsize(db.forms.find()[0])
@ozgun
ozgun / inject_hash.rb
Created December 5, 2012 09:40
Niye çalışmaz?
# Yukarıdaki kod çalıştırıldığında şöyle bir hata alınıyor.
# NoMethodError: undefined method `[]=' for 1:Fixnum
# from (pry):2:in `block in __pry__'
[1,2].inject({}) do |memo, obj|
memo[obj] = obj
end
# Ama aşağıdaki şekilde "merge" ile yazarsam çalışıyor ve şöyle bir çıktı üretiyor beklendiği üzere: {1=>1, 2=>2}
[1,2].inject({}) do |memo, obj|
memo.merge(obj => obj)
@ozgun
ozgun / _flash_messages.html.erb
Created December 14, 2012 14:03
Flash mesajlarının partial'da yazdırılması.
<%# partial'ın adı "_flash.html_erb" OLAMAMALI!!!!! %>
<% unless flash.empty? %>
<div class="flash">
<% flash.each do |k, v| %>
<%= content_tag :div, v, class: k.to_s %>
<% end %>
</div>
<% end %>
@ozgun
ozgun / capslock_ctrl.sh
Created January 11, 2013 11:52
Capslock - CTRL
setxkbmap -option ctrl:nocaps
@ozgun
ozgun / serving_files_with_nginx.txt
Last active August 23, 2016 03:03
Rails 3.2.x: Serving files with nginx using X-Accel-Redirect header (capistrano deploy)
# Assumptions:
* Rails 3.2.x
* nginx
* capistrano deploy
* "X-Accel-Mapping header missing" messages in nginx error.log file
* You want to serve static files with nginx instead of Rails
# nginx configuration:
@ozgun
ozgun / serving_files_with_nginx2.txt
Created January 17, 2013 16:44
Rails 3.2.x: Serving files with nginx using X-Accel-Redirect header (capistrano deploy) (2. method)
# Assumptions:
* Rails 3.2.x
* nginx
* capistrano deploy
* "X-Accel-Mapping header missing" messages in nginx error.log file
* You want to serve static files with nginx instead of Rails
# nginx configuration:
@ozgun
ozgun / gist:4620808
Created January 24, 2013 12:16
mongodb export & import
# export
$ mongoexport -d database -c collection > filename.json
# import
$ mongoimport -d database -c collection filename.json
@ozgun
ozgun / mongodb_timestamp_test.txt
Created January 24, 2013 12:31
mongodb timestamp test
> db.test.find()
{ "_id" : ObjectId("510128ee00000000ffffffff"), "a" : Timestamp(4294967290000, 2864434397), "b" : Timestamp(2005440768000, 287454020), "p" : Timestamp(4259970536000, 4194433536) }
@ozgun
ozgun / timestamp.txt
Created January 24, 2013 12:40
timestamp generated with mongo Ruby driver
> db.test_col.find()
{ "_id" : ObjectId("51012a6d8d74494bd8000001"), "a" : Timestamp(4294967295000, 4294967295) }
@ozgun
ozgun / generate_ts.rb
Last active December 11, 2015 15:29
Generating timestamps with mongo Ruby driver (Ruby code)
# encoding: utf-8
require 'json'
require 'mongo'
@conn = Mongo::Connection.new("localhost", 27017, safe: true)
@db = @conn['timestamp_test']
@coll = @db['test_col']
@coll.save({a: BSON::Timestamp.new(4294967295, 4294967295)})