Skip to content

Instantly share code, notes, and snippets.

@javan
javan / string-to-proc.md
Created August 7, 2014 22:05
Ruby String#to_proc
class String
  def to_proc
    Proc.new { |n| self.split(".").inject(n) { |n, method| n.send(method) } }
  end
end
>> Person.first(2).map(&"name.downcase.reverse.capitalize")
@javan
javan / application_controller.rb
Created November 30, 2013 22:06
Prevent cross-origin js requests
class ApplicationController < ActionController::Base
before_filter :ensure_xhr
private
def ensure_xhr
if request.get? && request.format && (request.format.js? || request.format.json?)
head :forbidden unless request.xhr?
end
end
end
@javan
javan / google-drive-mime-types.md
Last active August 13, 2025 17:34
Google Drive's undocumented MIME types

The Google Drive API supports these MIME types, but if you try to filter using them, you may find you're not getting the document types back that you expect. Especially when using setMimeTypes() with Google's JavaScript Picker.

Here are the poorly documented or completely undocumented MIME types I discovered:

If you want application/vnd.google-apps.document, also use application/vnd.google-apps.kix. Source.

If you want application/vnd.google-apps.spreadsheet, also use application/vnd.google-apps.ritz. Via a private email from a Google employee.

If you want application/vnd.google-apps.presentation, also use application/vnd.google-apps.punch. Source.

match = (element) ->
$(element).is "body, #workspace, #workspace > div.container"
$("html").bind "mousedown", (event) ->
if match event.target
event.preventDefault()
$("html").bind "dblclick", (event) ->
if match event.target
percentage = parseInt event.clientY / window.innerHeight * 100
@javan
javan / data-attr-hash.md
Created July 3, 2013 19:17
Supplying data-* html attributes as a hash with Rails helpers.

Just OK

link_to(person.name, person_path(person), "data-thing" => 1, "data-other-thing" => true)

<a data-other-thing="true" data-thing="1" href="/people/127326141-david-heinemeier">David Heinemeier Hansson</a>

Awesome!

@javan
javan / development.rb
Created April 16, 2013 15:33
Toggle features in development mode by touching various tmp/*.txt files.
# Touch tmp/caching.txt to turn on caching
if Rails.root.join('tmp/caching.txt').exist?
config.action_controller.perform_caching = true
config.cache_store = :mem_cache_store
else
config.action_controller.perform_caching = false
config.cache_store = :null_store
end
# Touch tmp/precompile.txt to test with asset precompiles. Run
@javan
javan / remove_hover.js.coffee
Created December 29, 2012 04:05
Remove :hover styles from mobile browsers
if 'createTouch' of document
ignore = /:hover\b/
try
for stylesheet in document.styleSheets
idxs = []
# detect hover rules
for rule, idx in stylesheet.cssRules
if rule.type is CSSRule.STYLE_RULE and ignore.test(rule.selectorText)
idxs.unshift idx

Dear Mr Makhmali

Thank you for your e-mail of 1 November 2012 regarding the SWITCHbasic domain names makhma.li and javanmakhma.li.

We regret to inform you that the deletion of the above domain names was not performed on time, on 12 october 2012. There is no possibility to make an exception concerning the invoice.

The subscription period for this domain names is 1st november 2012 until 31 october 2013. Since your termination was not performed 30 days prior to the start of the subscription period. At the latest on 1st of october 2012 (www.nic.ch/en/terms/ Paragraph 8.4 of the Registration Agreement), invoice No. 8895132 still has to be paid, despite the deletion.

Thank you for your understanding. If you have any questions, we will be pleased to assist you during our business hours.

Sep 11 09:48:37 javan-mba com.apple.SecurityServer[15]: Succeeded authorizing right 'com.apple.SoftwareUpdate.scan' by client '/Applications/App Store.app' [556] for authorization created by '/Applications/App Store.app' [556] (100003,0)
Sep 11 09:48:37 javan-mba com.apple.SecurityServer[15]: Succeeded authorizing right 'system.install.apple-software' by client '/Applications/App Store.app' [556] for authorization created by '/Applications/App Store.app' [556] (100003,0)
Sep 11 09:48:37 javan-mba com.apple.SecurityServer[15]: Succeeded authorizing right 'system.install.apple-software' by client '/System/Library/PrivateFrameworks/PackageKit.framework/Versions/A/Resources/installd' [588] for authorization created by '/Applications/App Store.app' [556] (4,0)
Sep 11 09:48:37 javan-mba com.apple.SecurityServer[15]: Succeeded authorizing right 'system.install.app-store-software' by client '/System/Library/PrivateFrameworks/PackageKit.framework/Versions/A/Resources/installd' [588] for authorization created by '/Appl
@javan
javan / gist:3237348
Created August 2, 2012 14:10
Sublime Text 2: Preferences > Key Bindings - User
[
// Make paste-and-indent the default paste behavior
{ "keys": ["super+v"], "command": "paste_and_indent" },
{ "keys": ["super+shift+v"], "command": "paste" }
]