Skip to content

Instantly share code, notes, and snippets.

@Fedcomp
Fedcomp / failsafe.rb
Last active March 30, 2017 07:14
Ruby exception handler that uses exception notifier to send exception notification and silently handles exception on production.
require 'exception_notification/rails'
# Capture errors in production and return nil
module Failsafe
def failsafe(&_block)
yield
rescue => e
# Show errors only during development
if Rails.env.test? || Rails.env.development?
raise e
def save_post_card
binding.pry
card = PostCard.where(:id => params[:post_card_id]).first
if card.nil?
render text: 'Nnot found postcard with provided ID', status: 404
return
end
text_data = params[:text_data]
name = params[:name].strip
@Fedcomp
Fedcomp / generator.php
Created October 24, 2016 13:22
IPV6 generator
<?php
$filename = "ip.list";
$prefix = "2a04:5200:8";
function generate_ipv6($prefix){
function generate_ipv6_block() {
$seed = str_split('1234567890abcdef');
shuffle($seed);
$block = join("", $seed); // Symbol array to string
$block = substr($block, 0, 4);
#!/usr/bin/env php
<?php
$filename = "ip.list";
$prefix = "2a04:5200:8";
$ips_amount = null;
if(isset($argv[1])){
$ips_amount = (int) $argv[1];
} else {
$ips_amount = 1;
@Fedcomp
Fedcomp / install_phantomjs.sh
Created June 28, 2016 14:30
Install fresh phantomjs (linux-x86_64)
#!/usr/bin/env bash
BUILD_REGEX="phantomjs-[0-9\.]+-linux-x86_64"
PHANTOM_VERSION=$(curl -s phantomjs.org/download.html | grep -oE $BUILD_REGEX | head -n 1)
PHANTOM_FILENAME="$PHANTOM_VERSION.tar.bz2"
PHANTOM_URL="https://bitbucket.org/ariya/phantomjs/downloads/$PHANTOM_FILENAME"
curl -L $PHANTOM_URL | \
tar xjf - -C /usr/local/bin --strip-components 2 $PHANTOM_VERSION/bin/phantomjs
@Fedcomp
Fedcomp / Gemfile
Created December 20, 2015 09:50
Rails taps working configuration Mysql -> Postgresql (Ubuntu 14.04/15.10) (20.12.2015)
source "https://rubygems.org"
gem 'taps', git: 'git://github.com/eric1234/taps.git', branch: 'patch-1'
gem 'mysql2'
gem 'sqlite3'
gem 'pg'
gem 'rack','1.0.1'
@Fedcomp
Fedcomp / gist:b6d542091db455ee830f
Last active August 29, 2015 14:23
Получить все внешние ссылки на веб странице
var curr_domain = window.location.href.split('//')[1].split('/')[0];
var outside_links = [];
var links = document.getElementsByTagName("a");
for(var i=0; i<links.length; i++) {
var res = links[i].href.split('//')[1];
if(typeof res == 'undefined') continue;
if(res.split('/')[0] == curr_domain) continue;
outside_links.push('http://' + res);
}
@Fedcomp
Fedcomp / psychostats_geoip_updater.php
Last active August 29, 2015 14:17
PHP Psychostats GeoIP updater
#!/usr/bin/env php
<?php
/*
========== Psychostats GeoIP updater ==============
Автор: Fedcomp
Для работы необходимо php расширение для работы ZIP.
php_zip.dll для windows.
Простой скрипт для обновления IP адресов стран в базе данных psychostats.
*/
@Fedcomp
Fedcomp / index.php
Created December 31, 2014 06:52
Sockets example: PHP handler example
<?php
/*
========== HTTP SOCKET EXAMPLE ==============
Автор: Fedcomp
https://github.com/Fedcomp/socket_example/
Связка из скрипта и плагина показывающая
как связаться из amxx плагина с php скриптом
и как этому скрипту обработать запрос
@Fedcomp
Fedcomp / gist:6403665
Created September 1, 2013 10:45
Миллисекунды в человеко-читаемый вид.
<?php
//echo 'Я знаю '.declOfNum(5, array('иностранный язык', 'иностранных языка', 'иностранных языков'));
function declOfNum($number, $titles)
{
$cases = array (2, 0, 1, 1, 1, 2);
return $number." ".$titles[ ($number%100>4 && $number%100<20)? 2 : $cases[min($number%10, 5)] ];
}
function seconds_to_words($seconds) {
if ($seconds < 0) return "Неизвестно";