Skip to content

Instantly share code, notes, and snippets.

View intrip's full-sized avatar
:octocat:
Coding, fun!

Jacopo Beschi intrip

:octocat:
Coding, fun!
View GitHub Profile
grep " 404 " * | cut -d " " -f 7 | sort | uniq -c | sort -n -r | head -50 | less
On hhtpd access log directory
@intrip
intrip / fake_cfs.rb
Created October 18, 2016 13:24
Italian fiscal code generator for Ruby on Rails
module Italian
# Generates a random fiscal code
class << self
@@generated_cfs = []
def cf
res = []
# ^[A-Z]{6}
res << _A_Z(6)
@intrip
intrip / .vimrc
Last active March 14, 2017 17:01
Custom .vimrc for ruby and javascript development
""""""""""""""""""
" Vundle options
"""""""""""""""""
set nocompatible " be iMproved, required
filetype off " required
:let mapleader = "-" " Maps - as leader character
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
# Base factorial version not tail recursive
def fact(n)
return 1 if n <= 1
n * fact(n-1)
end
# enable tail recursive optimization
RubyVM::InstructionSequence.compile_option = {
tailcall_optimization: true,
trace_instruction: false
@intrip
intrip / sort_deprecation_warning_uniq.sh
Created July 5, 2017 08:24
rails sort deprecation warnings uniq
ag 'DEPRECATION' log/development.log | awk -F 'DEPRECATION WARNING' '{print $2}' | sort -u
data = []
0.upto(2**(8*2)) do |i|
char = [i].pack("U*")
#puts "%04x" % i + ": " + char
data << char
end
p data, data.length
class Node
attr_accessor :value, :next_node, :prev_node
def initialize(value, next_node = nil, prev_node = nil)
@value = value
@next_node = next_node
@prev_node = prev_node
end
end
# Definition for a binary tree node.
# class TreeNode
# attr_accessor :val, :left, :right
# def initialize(val)
# @val = val
# @left, @right = nil, nil
# end
# end
# @param {TreeNode} root
require 'matrix'
require 'ruby_linear_regression'
ROWS_PER_OPTION = 1_000
POSITION_VALUES_MAPPING = {
top_left: { value: [1, 1], consent_rate: 60 },
bottom_left: { value: [1000, 1], consent_rate: 30 },
top_right: { value: [1, 1000], consent_rate: 45 },
bottom_right: { value: [1000, 1000], consent_rate: 20 },
require 'webrick'
require 'webrick/httpproxy'
# How to test it
#
# In a terminal:
# $ ruby delay_proxy.rb
#
# In another terminal:
# $ http_proxy=http://localhost:8001 curl http://www.google.it