Skip to content

Instantly share code, notes, and snippets.

View vdw's full-sized avatar

Dimitris Krestos vdw

View GitHub Profile
@vdw
vdw / gist:4f90e25aff0beba8b2de
Last active August 29, 2015 14:11
Create a swap file on CentOS 6.5

Check for existing swap files

swapon -s

Create swap file with 1024k size

sudo dd if=/dev/zero of=/swapfile bs=1M count=1024

sudo mkswap /swapfile

@vdw
vdw / gist:939a61dd3fbdb04dc5b8
Last active August 29, 2015 14:13
Dotted path to Ruby nested hash

Convert a dotted path to hash

def dotted_path_to_hash(hash)
  hash.map do |pkey, pvalue|
    pkey.to_s.split(".").reverse.inject(pvalue) do |value, key|
      {key.to_sym => value}
    end
  end.inject(&:deep_merge)
end
@vdw
vdw / gist:2fabb09c397e25d46930
Last active August 29, 2015 14:17
Sort array of objects based on given order of ids (ruby)
my_hash = {}

@objects.each { |obj| my_hash[obj.id] = obj }

my_array.collect{ |id| my_hash[id] }
@vdw
vdw / gist:eed289bb13de59160324
Last active August 29, 2015 14:17
Convert integer to scientific notation (javascript)
i = 1000
i.toExponential();

// 1e+3
@vdw
vdw / gist:3748557
Last active October 10, 2015 20:48
Basic CSS shortner rules

Basic CSS shortner rules

1) Trim white spaces

2) Remove new lines (/n) ~> single line

3) Remove last semi-column (;)

4) Hexadecimal color:

  • #FFFFFF becomes #fff (color is case-insensitive)
@vdw
vdw / carrierwave.rb
Created December 8, 2015 10:05
Set a remote path for assets
CarrierWave.configure do |config|
config.asset_host = proc do |file|
'http://www.domain.com'
end
end
@vdw
vdw / gist:5146681
Last active December 14, 2015 20:49
Basic Git commands

Basic Git commands

git init Initiate git in an existing project.

git clone git@repository_ssh Clone a project (you do not have to create a folder).

git add . Add any new files under version control.

git commit -am 'This is a message.' Commit the changes.

@vdw
vdw / gist:5205268
Last active December 15, 2015 04:59
Sublime Text 2 basic user settings

Sublime Text 2 basic user settings

Preferences.sublime-settings

{
	"auto_complete": true,
	"auto_complete_commit_on_tab": false,
	"auto_complete_delay": 50,
	"auto_complete_selector": "source - comment",
	"auto_complete_size_limit": 4194304,
@vdw
vdw / gist:5549622
Last active December 17, 2015 04:19
All about Sublime and its packages

Install Sublime Text 2 on Ubuntu

Add repository

sudo add-apt-repository ppa:webupd8team/sublime-text-2

Update

sudo apt-get update
@vdw
vdw / gist:5630003
Last active December 17, 2015 15:09
Basic CSS beautification rules

Basic CSS beautification rules

1) Order attributes alphabetically (not rules)