Skip to content

Instantly share code, notes, and snippets.

@stansidel
stansidel / reverse.scss
Last active December 21, 2015 07:29
Reversing z-index based from page render order http://stackoverflow.com/a/7033617/758990
#nav ul li {
@for $i from 1 through 20 {
&:nth-child(#{$i}) {
z-index: 1000 - $i
};
}
}
@stansidel
stansidel / bitrix2markdown.rb
Last active December 22, 2015 12:38
Ruby CSV sample
#!/usr/bin/env ruby
require "csv"
require "FileUtils"
require 'open-uri'
filename = ARGV[0]
skip_line = true
CSV.foreach(filename, { :col_sep => "\t" }) do |row|
@stansidel
stansidel / console-color-win.rb
Created September 7, 2013 07:50
Ruby console color working on Windows systems
require 'colorize'
require 'win32console'
puts 'A red line'.red
puts 'A green line'.green
@stansidel
stansidel / .gitignore.bitrix
Created September 8, 2013 06:12
Bitrix gitignore
upload/*
bitrix/*
!bitrix/templates/
!bitrix/php_interface/
bitrix/php_interface/dbconn.php
bitrix/components/bitrix/*
!bitrix/components/
!bitrix/modules/
bitrix/modules/*
@stansidel
stansidel / .gitignore
Last active December 22, 2015 15:38
Serving robots.txt depeding on the domain requested.
/robots*
!/robots.php
@stansidel
stansidel / check_redirects.rb
Created November 1, 2013 10:07
Check url redirects to be correct
#!/usr/bin/env ruby
# encoding: utf-8
`chcp 65001`
require 'rubygems'
require 'httpclient'
require 'csv'
filename = ARGV[0] || 'data/in.csv'
@echo off
rem Every second, check to see if volume is mounted
echo Waiting for volume…
:keepwaiting
ping -n 1 -w 1000 127.0.0.1 > nul
if not exist S:\ goto keepwaiting
start "Dropbox" "C:\Users\UserName\AppData\Roaming\Dropbox\bin\Dropbox.exe"
start "Google Drive" ""
@stansidel
stansidel / seed.rake
Last active January 4, 2016 05:29
Setting param with random records of another model
#rand(3..150).times do
# tender.items << Item.first(offset: rand(Item.count))
#end
# See http://hashrocket.com/blog/posts/rails-quick-tips-random-records
#tender.items = Item.where(Item.pluck(:id).shuffle[0..rand(3..150)])
# For Postgres
tender.items = Item.limit(rand(3..150)).order('RANDOM()')
# For MySQL
@stansidel
stansidel / monkey_patching.rb
Created January 23, 2014 10:27
Calling the overriden method from the new implementation
module Populator
class Record
# See http://stackoverflow.com/questions/4470108/when-monkey-patching-a-method-can-you-call-the-overridden-method-from-the-new-i
old_initialize = instance_method(:initialize)
define_method(:initialize) do |class_name, id|
old_initialize.bind(self).(class_name, id)
@class_name = class_name
end
def from_factory
@stansidel
stansidel / activate_swap.sh
Last active August 29, 2015 13:56
Activate swap file on Ubuntu (based on the tutorial for DigitalOcean - https://www.digitalocean.com/community/articles/how-to-add-swap-on-ubuntu-12-04)
sudo dd if=/dev/zero of=/swapfile bs=1024 count=1024k
sudo mkswap /swapfile
sudo swapon /swapfile
echo "/swapfile none swap sw 0 0 " | sudo tee -a /etc/fstab
echo 0 | sudo tee /proc/sys/vm/swappiness
echo vm.swappiness = 0 | sudo tee -a /etc/sysctl.conf
sudo chown root:root /swapfile
sudo chmod 0600 /swapfile
swapon -s