Skip to content

Instantly share code, notes, and snippets.

@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
@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 / 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'
@stansidel
stansidel / .gitignore
Last active December 22, 2015 15:38
Serving robots.txt depeding on the domain requested.
/robots*
!/robots.php
@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 / 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 / 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 / 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 / bx_update_elements.php
Created July 23, 2013 08:39
Updating all the elements of an IBlock (Bitrix). To use in the code console.
<?
if (CModule::IncludeModule("iblock")) {
$res = CIBlockElement::GetList(array(), array('IBLOCK_ID'=>23, 'ACTIVE'=>'Y'), false, false, array('NAME', 'ID', 'IBLOCK_ID', 'PROPERTY_FLAT_NUMBER'));
//$arElement = $res->Fetch();
//echo '<pre>'; var_dump($arElement); echo '</pre>';
while($arElement = $res->GetNext()) {
preg_match('(\d+)', ($arElement['NAME']), $matches);
$flatNumber = null;
if(count($matches) > 0) {
$flatNumber = intval($matches[0]);
#!/bin/bash
_file=$(mktemp -t "check_robots_internal_XXXXXX")
find /www/ -maxdepth 2 -name robots.txt | xargs grep "^[^#]*Disallow: /\s*$" -L > $_file
# First, try to copy the default robots.txt to all the dirs missing it
find /www/ -mindepth 1 -maxdepth 1 -type d '!' -exec test -e "{}/robots.txt" ';' -print0 | xargs -0 -I target_folder cp /www/0default/robots.txt target_fo
# If it somehow failed for some of the folders, then report
find /www/ -mindepth 1 -maxdepth 1 -type d '!' -exec test -e "{}/robots.txt" ';' -print >> $_file
if [ -s "$_file" ]