Skip to content

Instantly share code, notes, and snippets.

@stansidel
stansidel / Hash tags for tabs and history
Last active December 14, 2015 09:09
A tiny script that makes tabs links on the page work as if it's the same page. They don't generate loads of history entries. It uses the History API.
<html>
<head>
<title>Test page</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$('a.hash').on('click', function(e) {
var $this = $(this)[0];
e.preventDefault();
//window.history.location.hash="#hash";
@stansidel
stansidel / parse-rails-tutorial.rb
Last active December 14, 2015 13:58
Script parses the Rails Tutorial pages for code, listings and boxes and puts it to two files.
#!/usr/bin/env ruby
require 'rubygems'
require 'open-uri'
require 'nokogiri'
current_uri = 'http://ruby.railstutorial.org/chapters/beginning#top'
next_uri = true
depth = 13
head = <<HTML
03-23 22:47:08.233: ERROR/AndroidRuntime(307): FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{ru.alvik/ru.alvik.AvailabilityListActivity}: android.view.InflateException: Binary XML file line #42: Error inflating class <unknown>
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
at android.app.ActivityThread.access$2300(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
@stansidel
stansidel / bitrix_ya_events.html
Created March 27, 2013 09:02
A JS class for firing counters events (added to cart, sold) on any site (esp, Bitrix).
<html>
<head>
<script type="text/javascript">
var asproEvents = new function(){
var myWatchers = new Array();
this.addEventListener = function(watcher) {
console.log(typeof watcher);
}
this.raiseEvent = function(eventId) {
<?php
//событие подмены нужной цены для покупки услуг
AddEventHandler("catalog", "OnGetOptimalPrice", 'OnGetOptimalPriceHandler');
function OnGetOptimalPriceHandler($productID)
{
//получаем id инфоблока покупаемого товара. Если это услуга, то подменяем цену.
$db_iblock = CIBlockElement::GetList(array(), array("ID" => $productID), false, false, array("IBLOCK_ID"));
$iblock = $db_iblock->Fetch();
@stansidel
stansidel / gitrm.sh
Last active December 18, 2015 04:39 — forked from olistik/gitrm.sh
#!/bin/bash
# Performs a git rm on every deleted file.
deletion_list=$(git status | grep deleted: | cut -c 15-)
for file in $deletion_list; do
git rm --ignore-unmatch $file
done
@stansidel
stansidel / copy_robots_txt.sh
Created June 25, 2013 10:52
A command to copy a default robots.txt to all sites missing it
find /www/ -mindepth 1 -maxdepth 1 -type d '!' -exec test -e "{}/robots.txt" ';' -print0 | sudo xargs -0 -I target_folder cp /www/0default/robots.txt target_folder/ --preserve=mode,ownership
#!/bin/bash
result_file=$(mktemp -t "check_robots_final_XXXXX")
echo "# Checking servers..."
# Need to remove the Windows file endings
sites_file=$(mktemp -t "sites_XXXXXX")
sed 's/^M$//' /www/sitechecker/sites.txt > $sites_file
#!/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" ]
@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]);