Skip to content

Instantly share code, notes, and snippets.

View dimus's full-sized avatar

Dmitry Mozzherin dimus

  • University of Illinois
  • Champaign, IL, US
View GitHub Profile
@dimus
dimus / Hash.from_xml using Nokogiri
Created March 17, 2010 14:29
Adding Hash.from_xml method using Nokogiri
# USAGE: Hash.from_xml:(YOUR_XML_STRING)
require 'nokogiri'
# modified from http://stackoverflow.com/questions/1230741/convert-a-nokogiri-document-to-a-ruby-hash/1231297#1231297
class Hash
class << self
def from_xml(xml_io)
begin
result = Nokogiri::XML(xml_io)
return { result.root.name.to_sym => xml_node_to_hash(result.root)}
@dimus
dimus / main.go
Created March 13, 2022 11:49 — forked from pteich/main.go
Example for using go's sync.errgroup together with signal detection signal.Notify to stop all running goroutines
package main
import (
"context"
"errors"
"fmt"
"os"
"os/signal"
"syscall"
"time"
@dimus
dimus / .bashrc
Created September 25, 2011 15:08
Example of .bashrc
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
# don't put duplicate lines in the history. See bash(1) for more options
export HISTCONTROL=ignoredups
# ... and ignore same sucessive entries.
@dimus
dimus / cloudSettings
Last active July 3, 2021 01:52
Visual Studio Code Settings Sync Gist
{"lastUpload":"2021-07-03T06:52:55.905Z","extensionVersion":"v3.4.3"}
@dimus
dimus / main.go
Last active December 1, 2020 17:15
TaxonWorks API
package main
import (
"fmt"
"io/ioutil"
"net/http"
"github.com/gnames/gnlib/encode"
)
#!/usr/bin/env ruby
# encoding: utf-8
require 'rest_client'
HOST = "localhost"
res = RestClient.get("http://#{HOST}:6384")
puts "GET request"
puts res
@dimus
dimus / .git_colors
Created September 24, 2011 12:35
command line promt for git
#!/bin/bash
#
# Set our bash prompt according to the branch/status of the current git
# repository.
#
# Forked from http://gist.github.com/31934
RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
GREEN="\[\033[0;32m\]"
@dimus
dimus / .gemrc
Created September 24, 2011 13:35
Gemrc file
---
gem: --no-ri --no-rdoc
:backtrace: false
:benchmark: false
:bulk_threshold: 1000
:sources:
- http://gems.rubyforge.org/
- http://gems.github.com
:update_sources: true
:verbose: true
[user]
name=Your Name
email=your_email@example.org
[github]
user = your_github
[color]
branch=auto
diff=auto
status=auto
[color "branch"]
@dimus
dimus / damerau_levenshtein distance for ruby
Created July 14, 2009 15:48
Damerau-Levenshtein distance for ruby in C
#!/usr/bin/env ruby1.9
# encoding: UTF-8
require 'rubygems'
require 'inline'
require 'time'
class DamerauLevenshtein
def distance(str1, str2, block_size=2, max_distance=10)
res = distance_utf(str1.unpack("U*"), str2.unpack("U*"), block_size, max_distance)
(res > max_distance) ? nil : res