Skip to content

Instantly share code, notes, and snippets.

View ab9rf's full-sized avatar

Kelly Kinkade ab9rf

  • Western Suburban Chicagoland, Illinois
  • 21:02 (UTC -05:00)
View GitHub Profile
@ab9rf
ab9rf / autolabor_rb.rb
Created December 1, 2012 03:56
autolabor in ruby. haha.
class JobInfo
def get_bld (job)
id = job.references.find { |r| r.kind_of?(DFHack::GeneralRefBuildingHolderst) }
bld = df.world.buildings.all.binsearch(id.building_id) if id
bld
end
def self.const_labor (l)
lambda {|job| return l}
end
@ab9rf
ab9rf / gist:4180579
Created December 1, 2012 04:43
item type to hauling classification table (for DF)
HAUL_ITEM, /* BAR */
HAUL_ITEM, /* SMALLGEM */
HAUL_ITEM, /* BLOCKS */
HAUL_ITEM, /* ROUGH */
HAUL_STONE, /* BOULDER */
HAUL_WOOD, /* WOOD */
HAUL_FURNITURE, /* DOOR */
HAUL_FURNITURE, /* FLOODGATE */
HAUL_FURNITURE, /* BED */
HAUL_FURNITURE, /* CHAIR */
@ab9rf
ab9rf / tradeassist.rb
Last active December 21, 2022 08:42
DFHack Ruby script to mark items for purchase in trade screen
def is_tree_seed? (item)
if (!item.instance_of? DFHack::ItemSeedsst)
return false
end
if (item.mat_type < 419 || item.mat_type > 618)
return false
end
mat = df.world.raws.plants.all[item.mat_index]
@ab9rf
ab9rf / Colors.hs
Created March 13, 2013 04:37
A Haskell program I wrote as a CGI for a website I did some time ago.
module Main where
import Char
import Data.List
import Text.JSON
import System ( getArgs )
data RGBColor = RGB Double Double Double deriving (Show, Eq)
data XYZColor = XYZ Double Double Double deriving (Show, Eq)
@ab9rf
ab9rf / Mangle.hs
Created March 20, 2013 04:48
Grammar mangler. This code is a program I'm working on that I'm using to take the benighted grammar that PHP uses, simplify it, and infer types for nonterminals. I wrote it because I realized that the work I was doing to adapt the grammar was repetitive and tedious, so of course the only logical thing to do was write code to do it. At the moment…
module Main where
import qualified Data.Text as T
import qualified Text.Regex.PCRE.Light as R
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map
import Control.Monad.State
import Control.Monad (liftM)
@ab9rf
ab9rf / fizzbuzz.hs
Last active April 6, 2021 01:27
Silly haskell version of that FizzBuzz problem. Written because I was bored.
-- new and improved!
import Control.Applicative ((<|>))
import Data.Maybe (catMaybes)
nfilter n k = cycle $ take n $ (Just k) : (repeat Nothing)
joinf Nothing Nothing = Nothing
joinf Nothing (Just a) = Just a
joinf (Just a) Nothing = Just a
@ab9rf
ab9rf / drawTriangle.hs
Last active December 16, 2015 13:19
This is a Haskell implementation of the same algorithm as found here http://python.nulldoc.com/draw_triangle Solely for illustrative purposes; this isn't useful for anything.
drawTriangle size c s =
concat (map line [0..size-1])
where line i = map (charAt i) [0..size*2-1] ++ "\n"
charAt i j | size + i == j = c
| size - i == j = c
| (size - 1 == i) && (j > 0) = c
| otherwise = s
$Updates = "50ff45dd-fc70-4e32-8698-a3d112e59ef1", "c0b3230a-bb79-4e44-b771-177bc224fcbf", "5f84379f-7c14-472f-b560-62a0cdec6f31", "ca2a186f-626f-401f-9cb1-68f859acbbf7"
$updatefilter = ($Updates | % { "UpdateID = '$_'" } ) -join " or "
$us = New-Object -ComObject "Microsoft.Update.Session"
$ss = $us.createupdateSearcher()
Write-Host "Scanning for IE10 updates..."
$sr = $ss.search($updatefilter)
$uninst = $False
@ab9rf
ab9rf / gist:5637029
Created May 23, 2013 15:43
SQL stored procedure (Microsoft SQL Server 2008R2, may also work on 2008 or 2005, but no promises) to find and kill requests that are stuck in the ASYNC_NETWORK_IO state for long periods of time. This is typically caused by malfunctioning client software but can also be caused by network problems. Add the procedure to the master database, and se…
create procedure sp_terminate_stuck_network as
declare CRSR cursor for
select session_id from sys.dm_exec_requests
where wait_type = 'ASYNC_NETWORK_IO'
and wait_time > 5*60*1000 -- 5 minutes;
open CRSR;
declare @SESSION as int
@ab9rf
ab9rf / automelt.rb
Created January 4, 2014 18:30
Automelt script for Dwarf Fortress. Requires dfhack.
class AutoMelt
def initialize
end
def is_metal? (item)
item.respond_to?(:mat_type) && item.mat_type == 0 && df.world.raws.inorganics[item.mat_index].material.flags[:IS_METAL]
end
def is_meltable?(item)