Skip to content

Instantly share code, notes, and snippets.

@shikendon
shikendon / rijndael_128_cbc_encrypt.php
Created April 7, 2016 04:48
RIJNDAEL 128 CBC encryption PHP snippet
<?php
function addpadding($string, $blocksize = 32) {
$len = strlen($string);
$pad = $blocksize - ($len % $blocksize);
$string .= str_repeat(chr($pad), $pad);
return $string;
}
$key = '12345678901234567890123456789012';
$post_data_str = 'abcdefghijklmnop';
@shikendon
shikendon / rijndael_128_cbc_encrypt.rb
Created April 7, 2016 04:51
RIJNDAEL 128 CBC (AES-256-CBC) encryption Ruby snippet
require 'openssl'
key = '12345678901234567890123456789012'
iv = '1234567890123456'
data = 'abcdefghijklmnop'
cipher = OpenSSL::Cipher::AES.new(256, :CBC)
cipher.encrypt
cipher.padding = 32
cipher.key = key
@shikendon
shikendon / escape_unicode_control_characters.rb
Created April 24, 2016 04:54
轉譯 \t \r \n 以外的 Unicode 控制字元成 \uxxxx 的形式
class String
# Escape Unicode control characters except \t \r \n
def escape_unicode_control_characters
gsub(/(?<unicode_control_characters>[\p{C}&&[^\t\r\n]]+)/u) do |_match|
Regexp.last_match[:unicode_control_characters].unpack('U*').map { |i| '\u' + i.to_s(16).rjust(4, '0') }.join
end
end
end
require 'json'
require "heroku-api"
# heroku = Heroku::API.new(:api_key => API_KEY) # use API Key
# heroku = Heroku::API.new(:username => USERNAME, :password => PASSWORD) # use username and password
# heroku = Heroku::API.new(:headers => {'User-Agent' => 'custom'}) # use custom header
# NOTE: You can leave out the :api_key if ENV['HEROKU_API_KEY'] is set instead.
# https://github.com/heroku/heroku.rb
namespace :heroku do
#!/usr/bin/env ruby
require "benchmark"
require "httparty"
require "parallel"
# You need to modify your open file limit
# if you trying to run this on Mac OS
Benchmark.bmbm do |x|
x.report("Ruby Thread.new") do
#!/usr/bin/env python3
import threading
import urllib.request
def worker(index, results):
req = urllib.request.urlopen('https://www.facebook.com/')
results.append(req.getcode())
results = []
# lib/tasks/benchmark.rake
namespace :benchmark do
task run_sidekiq: :environment do
batch = Sidekiq::Batch.new
batch.on(:complete, TestWorker)
batch.jobs do
200.times do
TestWorker.perform_async
end
@shikendon
shikendon / start-fcrackzip.sh
Created April 1, 2017 07:22
Achieve fcrackzip parallel cracking by using xargs
logfile=$(date +%Y%m%d%H%M).log
targetfile=test.zip
# Start 1 processes for cracking mixalpha-numeric maximum 5 digits
fcrackzip -c Aa1 -b -l 1-5 --verbose -u $targetfile & >> $logfile &
# Start 62 processes for cracking mixalpha-numeric equal to 6 digits
eval echo\ {A..Z}AAAAA\; | xargs -I % -P 26 fcrackzip -c Aa1 -b -p % --verbose -u $targetfile >> $logfile &
eval echo\ {a..z}AAAAA\; | xargs -I % -P 26 fcrackzip -c Aa1 -b -p % --verbose -u $targetfile >> $logfile &
eval echo\ {0..9}AAAAA\; | xargs -I % -P 10 fcrackzip -c Aa1 -b -p % --verbose -u $targetfile >> $logfile &
@shikendon
shikendon / uptimerobot_discord.js
Last active April 21, 2021 11:52
Uptime Robot Discord integrations
// Alert Contact Type: Web-Hooks
// URL to Notify: https://discordapp.com/api/webhooks/{WEB_HOOK_ID}/{TOKEN}?
// POST Value (JSON Format):
{
"content": "Monitor is *alertTypeFriendlyName*: *monitorFriendlyName* ( *monitorURL* )\n```*alertDetails*```"
}
@shikendon
shikendon / vscode-user-settings.js
Last active August 23, 2022 11:58
My settings for Visual Studio Code
// Place your settings in this file to overwrite the default settings
// Extensions:
// - ESLint
// - Material Icon Theme
// - Material Theme Kit
// - Ruby
// - stylelint
{
"editor.scrollBeyondLastLine": false,
"editor.tabSize": 2,