Skip to content

Instantly share code, notes, and snippets.

@JaHIY
JaHIY / decode_base64.c
Last active September 11, 2015 04:41
base64 in C language
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <stdbool.h>
int main(void) {
const uint8_t base64chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
uint32_t buf = 0;
int8_t iter = 0;
bool enter_loop = true;
@JaHIY
JaHIY / strings.sh
Last active November 26, 2021 00:33
String-related functions in POSIX shell
#!/bin/sh -
substr() {
awk -v s="$1" -v i="$2" -v l="$3" 'BEGIN { print substr(s, i+1, l); }'
}
index() {
awk -v s="$1" -v c="$2" 'BEGIN { print index(s, c) - 1; }'
}
@JaHIY
JaHIY / operators.sh
Last active September 12, 2015 04:16
Bitwise operators in POSIX shell
#!/bin/sh -
calc() {
printf '%s\n' \
'define bit_and (x, y) {
auto min, max, d, i, ret
i = 1
ret = 0
if (x > y) {
min = y
@JaHIY
JaHIY / spawn.pl
Last active August 29, 2015 14:27
interprocess communication in perl
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use 5.014;
use experimental qw/smartmatch/;
use Carp qw/croak/;
use Data::Dumper;
@JaHIY
JaHIY / yanwenzi.json
Created May 15, 2015 06:45
A岛颜文字
{
"hacfun":[
"|∀゚",
"(´゚Д゚`)",
"(;´Д`)",
"(`・ω・)",
"(=゚ω゚)=",
"| ω・´)",
"|-` )",
"|д` )",
@JaHIY
JaHIY / perl2pkg.pl
Created April 4, 2015 16:19
convert perl module to PKGBUILD through metacpan API
#!/usr/bin/env perl
use strict;
use warnings;
use utf8::all;
use Carp;
use HTTP::Tiny;
use JSON qw(decode_json);
use Template;
@JaHIY
JaHIY / tax-calculator.tcl
Last active August 29, 2015 14:14
Tax Calculator
#!/usr/bin/env tclsh --
proc tax_calculate {money} {
if {$money <= 3500} {
return 0
}
set a [expr {$money - 3500}]
set tax_payment 0
while true {
if {$a <= 1500} {
@JaHIY
JaHIY / proxy.patch
Last active August 29, 2015 14:13
proxy.pac add another proxy
--- proxy_abp.pac 2015-01-11 00:22:39.000000000 +0800
+++ proxy_abp_modified.pac 2015-01-11 00:29:21.000000000 +0800
@@ -12,6 +12,15 @@
"@@userdefined.whitelist.com"
];
+//请修改代理
+var another_proxy = "SOCKS5 127.0.0.1:1080; SOCKS 127.0.0.1:1080; DIRECT;";
+
+//请添加规则
@JaHIY
JaHIY / qsort.lua
Created January 5, 2015 13:01
qsort in lua
#!/usr/bin/env lua
function qsort (t, lo, hi)
if lo > hi then
return
end
local p = lo
for i=lo+1, hi do
if (t[i] < t[lo]) then
p = p + 1
@JaHIY
JaHIY / reverse-file.lua
Created January 2, 2015 16:23
reverse file written in lua
#!/usr/bin/env lua
--[[
for line in io.lines(arg[0]) do
print(string.reverse(line))
end
--]]
local file = io.open(arg[0], "r")
file:seek("end", -1)
while true do