Skip to content

Instantly share code, notes, and snippets.

View nazarhussain's full-sized avatar
🎯
Focusing

Nazar Hussain nazarhussain

🎯
Focusing
View GitHub Profile
@nazarhussain
nazarhussain / signed_leb128_encode_decode.py
Last active July 11, 2021 04:20
LEB128 - Base 128 Varints Algorithm
from unsigned_leb128_encode_decode import decode_unsigned_leb128, encode_unsigned_leb128
# Python 3.7.4
def encode_signed_leb128(number):
# Higher multiple of 7
bits_multiple_of_7 = ((number.bit_length() + 7) // 7) * 7
twos_complement = (1 << bits_multiple_of_7) - number
@nazarhussain
nazarhussain / benchmarks_results.csv
Created April 17, 2020 14:18
Transaction Pool Benchmark Results
Max Transactions Transactions Per Account Spent Time Min Spent Time Max Spent Time Average Transaction Size Min Transaction Size Max Transaction Size Average
1024 16 2048 2048 2483 15470 15470 15626
1024 32 2124 2124 2348 15470 15470 15600
1024 48 2070 2070 2401 15470 15470 15561
1024 64 2132 2132 2431 15470 15470 15574
1024 80 1988 1988 2366 15470 15470 15587
1024 96 2054 2054 2383 15470 15470 15652
1024 112 2125 2125 2333 15470 15470 15600
1024 128 2108 2108 2302 15470 15470 15483
1024 144 2036 2036 2321 15470 15470 15574
# app/admin/email_previews.rb
ActiveAdmin.register_page 'Email Previews' do
content do
div '.'
end
sidebar 'Mail Previews' do
Dir['app/mailer_previews/*_preview.rb'].each do |preview_path|
preview_mailer = File.basename(preview_path, '.rb')
@nazarhussain
nazarhussain / pet_store_2_0.yml
Last active October 12, 2017 14:22
Swagger 2.0 vs OAS3.0
swagger: '2.0'
info:
description: This is a sample server Petstore server.
version: 1.0.0
title: Swagger Petstore
host: virtserver.swaggerhub.com
basePath: /nazarhussain/Swagger2/1.0.0
schemes:
@nazarhussain
nazarhussain / heap_diff.rb
Created May 19, 2017 18:02
Ruby Heap Diff
require 'set'
require 'json'
if ARGV.length != 2
puts "Usage: detect_leaks [FIRST.json] [SECOND.json]"
exit 1
end
first_addrs = Set.new
second_addrs = Set.new
@nazarhussain
nazarhussain / node-http-parser.js
Created February 29, 2016 07:51 — forked from threez/node-http-parser.js
In this example I played with the internal node http parser. This might be useful to folks that have to parse HTTP manually. For more info look at: https://github.com/joyent/node/blob/master/lib/_http_client.js
var HTTPParser = process.binding('http_parser').HTTPParser;
var parser = require("http").parsers.alloc();
parser.reinitialize(HTTPParser.RESPONSE);
parser.onBody = function(body) {
console.log(body.toString());
}
parser.onIncoming = function(response) {
console.log(response.headers);
console.log(response.statusCode);
@nazarhussain
nazarhussain / theme.css
Created October 15, 2015 20:21
jenkins-atlassian-theme
@-webkit-keyframes inprogress{0%{opacity:1}50%{opacity:.1}100%{opacity:1}}@-moz-keyframes inprogress{0%{opacity:1}50%{opacity:.1}100%{opacity:1}}Keyframes inprogress{0%{opacity:1}50%{opacity:.1}100%{opacity:1}}img[src$="blue.png"],img[src$="blue.gif"],img[src$="blue_anime.gif"],img[src$="yellow.png"],img[src$="yellow.gif"],img[src$="yellow_anime.gif"],img[src$="red.png"],img[src$="red.gif"],img[src$="red_anime.gif"],img[src$="grey.png"],img[src$="grey.gif"],img[src$="grey_anime.gif"],img[src$="disabled.png"],img[src$="disabled.gif"],img[src$="disabled_anime.gif"],img[src$="nobuilt.png"],img[src$="nobuilt.gif"],img[src$="nobuilt_anime.gif"],img[src$="aborted.png"],img[src$="aborted.gif"],img[src$="aborted_anime.gif"]{content:url('data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==');-webkit-border-radius:50%;-moz-border-radius:50%;padding:0;border-radius:50%;background:rgba(0,0,0,.1)}img[src*="blue.png"],img[src*="blue_anime.gif"]{background:#56a556!important}img[src*="yellow.png"],img[s
#!/bin/bash
# Author: Chmouel Boudjnah <[email protected]>
# Not officially supported by Rackspace only as a best effort basis :)
# Define yes to make it to copy to url to clipboard (via a shortened url
# service) You need to have the software xclip installed in your system.
COPY_URL_TO_CLIPBOARD=yes
# Containers to ignore in the list
CONTAINERS_TO_IGNORE=".CDN_ACCESS_LOGS"
@nazarhussain
nazarhussain / check_boxes_with_hints.rb
Created August 29, 2012 21:02
Custom Collection Inputs Simple Form
module SimpleForm
class FormBuilder
def collection_check_boxes_with_hints(attribute, collection, value_method, text_method, options={}, html_options={})
rendered_collection = render_collection(
collection, value_method, text_method, options.merge({:item_wrapper_tag => nil}), html_options
) do |item, value, text, default_html_options|
default_html_options[:multiple] = true
builder = instantiate_builder(SimpleForm::ActionViewExtensions::CheckBoxBuilder, attribute, item, value, text, default_html_options)
label = builder.label(:class => 'inline checkbox checkbox_with_hints').split("</")
[
@nazarhussain
nazarhussain / sha1.rb
Created February 8, 2012 05:59
Custom Encryptor for Devise
module Devise
module Encryptors
class Sha1
def self.digest(password, user_salt)
string_to_hash = password + "abcdefgh" + user_salt
Digest::SHA1.hexdigest(string_to_hash)
end
def self.salt(username)
self.object_id.to_s + rand.to_s