Skip to content

Instantly share code, notes, and snippets.

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
/**
* Auto-generated code below aims at helping you parse
* the standard input according to the problem statement.
**/
@pbrit
pbrit / gist:57a2a8124cf726c9fee5
Created December 18, 2014 13:21
base32_util.rb
def hex_to_base32(hex)
alphabet = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','2','3','4','5','6','7']
bin_array = hex.split('').each_slice(2).map(&:join).map { |el| el.to_i(16) }.map do |el|
str = el.to_s(2)
prefix_length = 8 - str.length
"#{'0' * prefix_length}#{str}"
end
bin_array.join.split('').each_slice(5).map(&:join).map { |el| alphabet[el.to_i(2)] }.join
IPAddr.new('10.0.0.0/8').to_range.each_slice(256).map(&:first).map { |ip| ip.mask(8 * (4 - ip.to_s.split('.').reverse.take_while(&'0'.method(:==)).count)) }
@pbrit
pbrit / conf.c
Created July 1, 2014 14:20
Part of sendmail where setprocname can be found. (Hint: SPT_NONE)
/*
* Copyright (c) 1998-2013 Proofpoint, Inc. and its suppliers.
* All rights reserved.
* Copyright (c) 1983, 1995-1997 Eric P. Allman. All rights reserved.
* Copyright (c) 1988, 1993
* The Regents of the University of California. All rights reserved.
*
* By using this file, you agree to the terms and conditions set
* forth in the LICENSE file which can be found at the top level of
* the sendmail distribution.
@pbrit
pbrit / gist:0e0fb786c0bd44885493
Created June 26, 2014 19:07
Three version of Fibonacci sequence
(defn fib-1 [n]
(if (< n 3)
1
(+ (fib-1 (- n 1))
(fib-1 (- n 2)))))
(defn fib-2 [n]
(let [ lazy-fib ((fn lazy-gen [n1 n2]
(cons (+ n1 n2)
(lazy-seq
@pbrit
pbrit / gist:d6efe6317d53fc85711c
Last active August 29, 2015 14:01
Rake task for gitlab
namespace :'mail.ru' do
namespace :user do
#
# Usage:
# $rake mail.ru:user:disable USERNAME=p.chechetin or $rake mail.ru:user:disable EMAIL=p.chechetin@corp.mail.ru
#
# Exit code:
# 0 => Success
# 1 => Failure
#
require 'yaml'
module Puppet::Parser::Functions
newfunction(:generate_role, :type => :rvalue) do |args|
fact = args[0]
path = args[1]
default = args[2]
@pbrit
pbrit / gist:9713531
Created March 22, 2014 20:13
Fix for ruby with Xcode 5.1
82c82
< CONFIG["LIBRUBY_DLDFLAGS"] = "-undefineddynamic_lookup -multiply_definedsuppress -install_name $(libdir)/$(LIBRUBY_SO) -current_version $(MAJOR).$(MINOR).$(TEENY) -compatibility_version $(ruby_version) $(XLDFLAGS)"
---
> CONFIG["LIBRUBY_DLDFLAGS"] = "-undefineddynamic_lookup -multiply_defined suppress -install_name $(libdir)/$(LIBRUBY_SO) -current_version $(MAJOR).$(MINOR).$(TEENY) -compatibility_version $(ruby_version) $(XLDFLAGS)"
125c125
< CONFIG["DLDFLAGS"] = "-undefineddynamic_lookup -multiply_definedsuppress"
---
> CONFIG["DLDFLAGS"] = "-undefineddynamic_lookup -multiply_defined suppress"
@pbrit
pbrit / gist:7142489
Created October 24, 2013 18:27
Heal RubyGems on 10.9 Maverics
sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include
@pbrit
pbrit / gist:6713655
Created September 26, 2013 12:45
Load Gemfile.lock to ruby
Bundler::LockfileParser.new(IO.read('./Gemfile.lock'))