Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
# https://stackoverflow.com/a/78062608/240443
# Inspired by glenn jackman's awesome '$(NF-1) == "" {$(NF-1) = $NF} {NF--} 1' trick
file1=$1
file2=$2
key=${3:-name}
sep=${4:-|}
key1=$(head -1 "$file1" | awk -v FS="$sep" -v key="$key" '{ for (i = 1; i <= NF; i++) if ($i == key) print i }')
@amadanmath
amadanmath / langdetect_restricted.py
Last active August 28, 2018 03:36
Using langdetect with a restricted set of languages
from langdetect.detector_factory import DetectorFactory, PROFILES_DIRECTORY
import os
def get_factory_for(langs):
df = DetectorFactory()
profiles = []
for lang in ['en', 'ru', 'pl']:
with open(os.path.join(PROFILES_DIRECTORY, lang), 'r', encoding='utf-8') as f:
profiles.append(f.read())
df.load_json_profile(profiles)
@amadanmath
amadanmath / keybase.md
Created February 8, 2018 07:55
Keybase proof

Keybase proof

I hereby claim:

  • I am amadanmath on github.
  • I am amadan (https://keybase.io/amadan) on keybase.
  • I have a public key ASAj05NMOoBTV-DRI03KNrjzXucunCbptVKRPX8vU3w75Qo

To claim this, I am signing this object:

@amadanmath
amadanmath / biggest_box_size.rb
Created August 17, 2017 02:03
Biggest box size, using dynamic programming
#!/usr/bin/env ruby
input = [
[1,0,0,0,1,0,0,0,0,1,0,0,0,0,0],
[1,0,0,0,1,0,0,0,0,0,0,0,0,0,0],
[1,0,0,0,1,0,0,0,0,1,0,0,0,0,0],
[1,0,1,0,1,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,1,1,0,1,0,0,0,0,0],
[0,0,0,0,0,0,0,1,0,0,0,0,1,0,0],
[0,0,0,0,0,0,1,0,0,0,0,1,0,0,0],
@amadanmath
amadanmath / KaTeX_for_Gists.user.js
Last active August 29, 2015 14:07
KaTeX for Gists user extension
// ==UserScript==
// @name KaTeX for Gists
// @author Goran Topić
// @homepage http://github.com/amadanmath/
// @include *://gist.github.com/*
// @version 0.1.1
// @updateURL https://gist.github.com/amadanmath/6eaf4cc850f38b78562f/raw/KaTeX_for_Gists.user.js
// @downloadURL https://gist.github.com/amadanmath/6eaf4cc850f38b78562f/raw/KaTeX_for_Gists.user.js
// @description Shows LaTeX in <tt> tags on Github Gist pages
// ==/UserScript==
@amadanmath
amadanmath / rubygolf.rb
Created November 22, 2011 05:23
Ruby Golf
# Written against Ruby 1.9.2
# Hole #1: FizzBuzz
# I accidentally saw Cyrus's solution before trying my own, so no attempt
# Hole #2: Caesar Cipher
# Works only for `[a-zA-Z]*`
def caesar(f,x)
f.each_char.map{|c|t=c.ord+x;(t-1)&31>25&&t+=x<0?26:-26;t.chr}*''
end