Skip to content

Instantly share code, notes, and snippets.

View vdw's full-sized avatar

Dimitris Krestos vdw

View GitHub Profile
@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:eed289bb13de59160324
Last active August 29, 2015 14:17
Convert integer to scientific notation (javascript)
i = 1000
i.toExponential();

// 1e+3
@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:09efee4f264bb2630345
Last active January 31, 2023 08:55
Kill tcp connection with tcpkill on CentOS

Install tcpkill
yum -y install dsniff --enablerepo=epel

View connections
netstat -tnpa | grep ESTABLISHED.*sshd.

Block with ip tables
iptables -A INPUT -s IP-ADDRESS -j DROP

Kill connection

@vdw
vdw / gist:f3c832df8ce271a036f2
Last active January 19, 2018 10:53
Ruby hash to dotted path

Convert a ruby hash to dotted path

def hash_to_dotted_path(hash, path = "")
  hash.each_with_object({}) do |(k, v), ret|
    key = path + k.to_s

    if v.is_a? Hash
      ret.merge! hash_to_dotted_path(v, key.to_s + ".")
 else
@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: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:5640164
Created May 23, 2013 23:04
Development Enviroment

Install MySQL server in Ubuntu

1) sudo apt-get install mysql-server

2) sudo apt-get install php5-mysql for php

3) sudo apt-get install libmysql-ruby for ruby

@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)

@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