Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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
#!/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;
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 / 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
@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 "Неизвестно";
@Fedcomp
Fedcomp / easy_replay_capturing.bat
Created October 17, 2017 23:57
Simple batch file to create replay folders
mkdir %appdata%\Carbon\.debug\replay
mkdir %appdata%\Carbon\Airmech\.debug\replay
mkdir %appdata%\Carbon\AirmechCanary\.debug\replay
mkdir %appdata%\Carbon\AirmechSteam\.debug\replay
@Fedcomp
Fedcomp / hashifier.rb
Created October 21, 2018 18:14
Hash all files in directory
require 'pathname'
require 'digest'
Pathname.new(Dir.pwd).children.select(&:file?).each do |file|
next if file.basename.to_s.start_with?('hashed_') || file.extname == '.rb'
file_md5 = Digest::MD5.file(file).hexdigest
old_name = file.basename
new_name = "hashed_#{file_md5}_#{old_name}"
puts "#{old_name} -> #{new_name}"
File.rename old_name, new_name