Skip to content

Instantly share code, notes, and snippets.

View armanm's full-sized avatar

Arman Mirkazemi armanm

View GitHub Profile
@armanm
armanm / gist:4736034
Created February 8, 2013 02:02
To parse YAML with Ruby, do not use the YAML module, use Psych (which ships with Ruby 1.9.2, though there is also a gem). The reason is that YAML uses the unmaintained Syck library, whereas Psych uses the modern LibYAML:
>> require 'yaml'
>> YAML.load("%YAML 1.1\n---\n'test'") # %YAML directive not supported
=> "%YAML 1.1 --- 'test'"
>> require 'psych'
>> Psych.load("%YAML 1.1\n---\n'test'") # all good
=> "test"
@armanm
armanm / gist:5022374
Last active December 14, 2015 03:39
Nginx config for PHP-FPM
server {
sendfile off;
listen 80 default;
server_name localhost;
client_max_body_size 10m;
access_log /var/log/nginx/localhost.access.log;
location / {
root /vagrant;
@armanm
armanm / migration.rb
Created March 22, 2013 10:51
Paperclip doesn't give you image dimensions. I saw a bunch of different implementations and didn't like em. So I rolled my own. This implementation will save the `width` and `height` of images to the model in which you define your `has_attachmented_file` field.
# this migration allows to have polymorphic models
class CreateAssets < ActiveRecord::Migration
def self.up
create_table :assets, :force => true do |t|
t.string :type
t.integer :assetable_id
t.string :assetable_type
t.string :attachment_file_name
t.string :attachment_content_type
@armanm
armanm / gist:5233820
Created March 24, 2013 22:20
View members of a group on Ubuntu machines using command line:
sudo apt-get install members
members some_group_name
@armanm
armanm / gist:5235071
Last active December 15, 2015 08:59
This is how to run a one off but long running rake task in the background. The ampersand in the end allows to run commands in background mode, but the `nohup` part in the beginning stops the app from receiving termination signal when the SSH session is closed. This allows for the app to run continuously in the background.
nohup rake RAILS_ENV=production rake some_task &
@armanm
armanm / setup.md
Last active December 15, 2015 14:39 — forked from leesmith/setup.md

Ruby on Rails development setup on Ubuntu 12.04

System update

# change mirror to ubuntu.osuosl.org first
sudo apt-get update

Install common libraries

@armanm
armanm / readme.md
Last active December 15, 2015 15:09

How to install rbenv globally

Cloned the rbenv repository to /usr/local/rbenv.

git clone git://github.com/sstephenson/rbenv.git /usr/local/rbenv/

Cloned ruby-build into /usr/local/rbenv/plugins so it’s quick and easy for the system administrator to install different Ruby versions.

@armanm
armanm / gist:5393730
Created April 16, 2013 06:08
This shell script lets you check who can login to your server using SSH keys
#!/bin/sh
#
# check who can login to a user's account
#
check_user()
{
local IFS=:
while read user home; do
test -e $home/.ssh/authorized_keys || continue
cut -d' ' -f3 $home/.ssh/authorized_keys | sed -e "s/^/user $user: /"
@armanm
armanm / gist:5417740
Created April 19, 2013 02:42
Shell script for sending files from command line to trash on OSX
#!/bin/bash
#
# trash - Move files to the appropriate .Trash file on Mac OS X. (Intended
# as an alternative to 'rm' which immediately deletes the file.)
#
# v0.1 2007-05-21 - Morgan Aldridge <morgant@makkintosshu.com>
# Initial version.
# v0.2 2010-10-26 - Morgan Aldridge
# Use appropriate .Trashes folder when trashing files

How to set Ubuntu timezone to UTC

execute the following command:

sudo dpkg-reconfigure tzdata

and then select UTC from the list