Skip to content

Instantly share code, notes, and snippets.

View fbehrens's full-sized avatar
🎯
Focusing

Frank Behrens fbehrens

🎯
Focusing
  • https://github.com/Bayer-Group
  • Cologne - Germany
  • X @bluse1995
View GitHub Profile
data = <<-HERE
chile,santiago,5000000,02
chile,valparaiso,100000,55
chile,la serena,80000,56
usa,los angeles,15000000,44
usa,washington dc,500000,88
china,beijing,14000000,98
HERE
result = Hash.new{|h,k| h[k] = [] }
@fbehrens
fbehrens / feiertage -2013
Created April 12, 2010 12:33
feiertage.rb
require 'rubygems'
require 'mechanize'
agent = Mechanize.new
agent.set_proxy('proxy', 8080, 'user', 'secret')
page = agent.get( 'http://www.feiertage.net/frei-tage.php')
h = {}
%w(2010 2011 2012 2013).each do |year|
f = page.forms.first
f.state = 'NW'
f.year = year
@fbehrens
fbehrens / launch batchcommands with .pid blocking
Created August 5, 2010 08:19
process commands with pid file
#rakefile
require 'rake'
extend FileUtils
PID = '.pid'
task :default => :reset
module Kernel
def pid
raise "pid file already exists" if File.exists? PID
touch PID
@fbehrens
fbehrens / generate ssl keystore
Created October 8, 2010 11:46
generate_certificate.rb
require 'rubygems'
require 'highline/import'
puts "usage ruby generate_keystore.rb host password"
def read_certificate
answer = [ ask("and paste generated Certificate here >>\n") ]
until (answer << ask("") ).last.include? "END CERTIFICATE"
end
answer.join("\n")
@fbehrens
fbehrens / remove_dublicates.rb
Created January 12, 2011 05:45
iterates over files and delete dublicates
require 'digest/md5'
require 'fileutils'
hash = {}
["/Users/frankbehrens/Desktop/niels\ backup/Pictures/iPhoto\ Library/Originals/**/*.*","**/*.*"].each do |dir|
Dir.glob(dir).each do |file|
print '.'
digest = Digest::MD5.hexdigest(File.read(file))
if hash[digest]
puts "#{file}is dublicate"
FileUtils.rm file
@fbehrens
fbehrens / monitor.rb
Created February 20, 2011 11:59
litte script which monitors my internetconnection
#!/usr/bin/ruby -w
# this is an example of uncommunicative code
# would be a good example for refactoring to make clear what it does
class Monitor
@@host = "heise.de"
@@tries = 4
@@results_per_line = 60
@@log = __FILE__.gsub(/rb$/,"log")
@fbehrens
fbehrens / gist:2056193
Created March 17, 2012 07:35
Using multiple databases in Active Record
equire 'oci8'
require 'activerecord-oracle_enhanced-adapter'
require 'active_record'
class Db1 < ActiveRecord::Base
self.abstract_class = true
establish_connection YAML.load_file('config/database.yml')['db1']
end
class Db2 < ActiveRecord::Base
@fbehrens
fbehrens / csv.fs
Created November 11, 2015 09:50
Hourly filtering
module wba.csv
open FSharp.Data
open System
type Stocks = CsvProvider<"ES.csv", Schema = "Date(string),Time(string),Open,High,Low,Close,Volume">
let getTime (row:Stocks.Row) =
let iC = Globalization.CultureInfo.InvariantCulture
let s = row.Date + " " + row.Time
DateTime.ParseExact(s, "MM/dd/yyyy HHmm",iC)
@fbehrens
fbehrens / HashFromCsv.ps1
Created February 26, 2020 21:15
PSReadline Handler
Set-PSReadLineKeyHandler -Chord F2 -BriefDescription HashFromCsv -LongDescription "converts a comma separated String int a Hashtable" -ScriptBlock { param($key, $arg)
$line = $null
$cursor = $null
[Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$line, [ref]$cursor)
$g = [Regex]::matches($line,"\S+") | ? { $_.index -le $cursor -and $_.index + $_.Length -ge $cursor }
if (!$g){ return }
$s = $g.value -replace ",",'="";'
$s = "@{$s=`"`"}"
$pos = $s.IndexOf('""')
[Microsoft.PowerShell.PSConsoleReadLine]::Replace($g.Index,$g.Length,$s)
filter Decode { [System.Net.WebUtility]::UrlDecode($_) }
filter Get-Songs{
$xml = New-Object XML.XmlDocument
$xml.LoadXml((Get-Content $_))
$disk = $xml.BPP.disc
$outFile = $_.name -replace "\.bpp$",".mp3"
$(0..($disk.path.Length -1) | % {
"$($disk.path[$_].src | Decode)$($disk.file[$_].src | Decode)"
} )> $outFile