Skip to content

Instantly share code, notes, and snippets.

@JaHIY
JaHIY / uniq_array.cpp
Last active March 27, 2022 08:08
uniq array in-place
#include <iostream>
using std::cout;
using std::endl;
#include <vector>
using std::vector;
#include <algorithm>
using std::swap;
@JaHIY
JaHIY / tgvs-to-gif.sh
Last active March 23, 2022 11:23
convert telegram video sticker (webm) to animated gif
#!/usr/bin/env sh
find . -name '*.webm' -type f -print0 | xargs -0 -I'{}' -n 1 -- bash -c 'ffmpeg -y -loglevel warning -c:v libvpx-vp9 -i "$0" "${0%.*}.webp"' '{}'
gimp -d -f -n -i -b '(define (webp->gif filename) (let* ((image (car (file-webp-load RUN-NONINTERACTIVE filename filename))) (drawable (car (gimp-image-get-active-layer image))) (new-filename (string-append (substring filename 0 (- (string-length filename) 5)) ".gif"))) (gimp-image-convert-indexed image CONVERT-DITHER-NONE CONVERT-PALETTE-GENERATE 255 FALSE TRUE "") (file-gif-save RUN-NONINTERACTIVE image drawable new-filename new-filename FALSE TRUE 0 2) (gimp-image-delete image))) (define (batch-webp->gif pattern) (let* ((filelist (cadr (file-glob pattern 1)))) (for-each webp->gif filelist))) (batch-webp->gif "*.webp")' -b '(gimp-quit 0)'
@JaHIY
JaHIY / replaceAll.cpp
Created February 26, 2022 10:21
replaceAll function in C++
#include <iostream>
using std::cout;
using std::endl;
#include <string>
using std::string;
using std::basic_string;
#include <string_view>
using std::basic_string_view;
@JaHIY
JaHIY / PKGBUILD
Last active October 12, 2019 08:18
Arch Linux PKGBUILD for nim 1.0.0
# Modified by JaHIY (https://github.com/JaHIY)
# Maintainer: Levente Polyak <anthraxx[at]archlinux[dot]org>
# Contributor: Alexander F Rødseth <[email protected]>
# Contributor: Dominik Picheta <[email protected]>
# Contributor: Sven-Hendrik Haase <[email protected]>
# Contributor: Jesus Alvarez <[email protected]>
pkgname=nim
pkgver=1.0.0
@JaHIY
JaHIY / yanghui.fs
Last active August 5, 2018 14:11
Yang Hui's triangle, Pascal's triangle in F#
let rec getNext' (line : int list) result i =
if i < (List.length line) - 1 then
getNext' line ((line.[i] + line.[i + 1]) :: result) (i + 1)
else
1 :: result
let getNext line =
getNext' line [1] 0
let rec get' n result i =
@JaHIY
JaHIY / soundex.erl
Last active April 12, 2018 13:07
Soundex algorithm in Erlang
#!/usr/bin/env escript
%% -*- erlang -*-
%%! -smp enable -sname soundex -mnesia debug verbose
main([String]) ->
Word = soundex(String),
io:format("~s => ~s\n", [String, Word]);
main(_) ->
usage().
@JaHIY
JaHIY / with.tcl
Last active May 4, 2016 06:46
Tcl: `with` proc from `with-open` in clojure
#!/usr/local/opt/tcl-tk/bin/tclsh
package require Tcl 8.6
proc with {args} {
set lengthOfArgs [llength $args]
if {($lengthOfArgs % 2) == 0} {
return -code error {wrong # args: should be "with ?varName1 channelId1 varName2 channelId2 ...? command"}
}
if {$lengthOfArgs == 1} {
@JaHIY
JaHIY / flatten.pl
Last active December 31, 2015 04:20
flatten list in perl
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use 5.014;
use Data::Dumper;
sub flatten (+) {
@JaHIY
JaHIY / morse_decode.p6
Last active December 23, 2015 04:01
Morse code translator in 1 line of perl6.
my %h = <.--.-. @ ...-..- $ .-..-. " ..--.- _ -....- - .-.-. + -...- = -.-.-. ; ---... : ----- 0 ----. 9 ---.. 8 --... 7 -.... 6 ..... 5 ....- 4 ...-- 3 ..--- 2 .---- 1 .--.-. @ -..-. / ..--.. ? --..-- , .-.-.- . --.. Z -.-- Y -..- X .-- W ...- V ..- U - T ... S .-. R --.- Q .--. P --- O -. N -- M .-.. L -.- K .--- J .. I .... H --. G ..-. F . E -.. D -.-. C -... B .- A>; for lines() { say .split(/<space>/).map({ %h{$_} // $_ }).join }
@JaHIY
JaHIY / check_params.pl
Last active September 16, 2015 13:53
wrap compile function in Type::Params
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use 5.010;
use Data::Dumper;
use Type::Params qw(compile);
use Types::Standard -types;