Skip to content

Instantly share code, notes, and snippets.

View Sija's full-sized avatar

Sijawusz Pur Rahnama Sija

View GitHub Profile

Keybase proof

I hereby claim:

  • I am sija on github.
  • I am sija (https://keybase.io/sija) on keybase.
  • I have a public key whose fingerprint is 7D5B 64C2 BA55 F96F D21B 8843 1551 5E26 9AB4 D86A

To claim this, I am signing this object:

@Sija
Sija / actionmailer_i18n_monkeypatch.rb
Created July 1, 2015 00:27
Make Rails' 4.2 ActionMailer locale aware or i18n for ya emailz
module ActionMailer
class MessageDelivery
private
def enqueue_delivery(delivery_method, options={})
args = @mailer.name, @mail_method.to_s, delivery_method.to_s, I18n.locale.to_s, *@args
ActionMailer::DeliveryJob.set(options).perform_later(*args)
end
end
class DeliveryJob
def perform(mailer, mail_method, delivery_method, locale, *args) # :nodoc:
@Sija
Sija / EasyXML.class.php
Created January 19, 2011 09:07
XML manipulation class found in dark corners of my hdd
<?php
/**
*
* @mainpage
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
@Sija
Sija / merge.coffee
Created May 1, 2011 09:30
Object.merge
merge = (target, objects...) ->
deep = yes
if typeof target is 'boolean'
[deep, target] = [target, objects.shift()]
if not objects.length
[target, objects] = [this, [target]]
isExtendable = (object) ->
typeof object is 'object' and object isnt null or
@Sija
Sija / typeOf-alt.coffee
Last active September 25, 2015 23:08
Object.type
# Execute function immediately
typeOf = do ->
classToType = {}
for name in 'Boolean Number String Function Array Date RegExp Undefined Null'.split ' '
classToType["[object #{name}]"] = name.toLowerCase()
# Return a function
(obj) ->
strType = Object::toString.call obj
classToType[strType] or 'object'
@Sija
Sija / unicorn
Last active September 29, 2015 19:57
Unicorn init.d script
#!/bin/sh
### BEGIN INIT INFO
# Provides: unicorn
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: unicorn initscript
# Description: Unicorn is an HTTP server for Rack application
### END INIT INFO
@Sija
Sija / db.rake
Created June 3, 2012 12:40
YAML data seeds importer for Rails 3
require 'active_record/fixtures'
namespace :db do
desc 'Seed the database with once/ and always/ fixtures.'
task :seed => :environment do
load_fixtures 'seed/once'
load_fixtures 'seed/always', :always
end
desc 'Seed the database with develop/ fixtures.'
@Sija
Sija / NSArray-Blocks.h
Created November 15, 2009 05:22
Making NSArray more ruby-ish
//
// NSArray-Blocks.h
// Handy codebits
//
// If you want to keep block definitions terse, simple and dynamic, have no
// problems with the incompatible block pointer types and you don't mind
// compiler warnings about sending a message without matching signature,
// DO NOT IMPORT THIS FILE, seriously.
//
// Created by Sijawusz Pur Rahnama on 15/11/09.
moduleKeywords = ['extended', 'included']
class Module
@extend: (obj) ->
for key, value of obj when key not in moduleKeywords
@[key] = value
obj.extended?.apply(@)
this
@Sija
Sija / dimensions_validator.rb
Last active December 27, 2015 12:49
DimensionsValidator to use for images uploaded using Paperclip.
class DimensionsValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
temp_file = value.queued_for_write[:original]
return unless temp_file.present?
return unless geo = Paperclip::Geometry.from_file(temp_file)
options.slice(:width, :height).each_pair do |key, expectation|
next unless dimension = geo.send(key)
case expectation