This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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") | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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] = [] } |
NewerOlder