Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env ruby
# Changes file extension, e.g:
# $ cext some/file/deeply/nested/file.png .jpg
# $ ls some/file/deeply/nested
# file.jpg
nametokens = ARGV.first.split '.'
newext = ARGV[1].split '.'
File.rename ARGV.first, (nametokens[-newext.length, newext.length] + newext).join '.'
if defined? ActiveRecord
def explain(query)
query = query.to_sql if query.respond_to? :to_sql
ActiveRecord::Base.connection
.execute("EXPLAIN ANALYZE #{query}")
.to_a
.each { |hash| puts hash["QUERY PLAN"] }
nil
Harbour.registerPlugin({
name: "Harbour HTTP",
foo: function(...) { ... },
....
});
Harbour.prototype.parseTargets = function(callback) {
var longestIP, longestHost;
var newTargets = [];
var oldTargets = this.options.targets.split(',');
var remaining = oldTargets.length;
oldTargets.forEach(function(target){
if(net.isIP(target)){
dns.reverse(target, function(err, domains){
newTargets.push([(domains ? domains[0] : ''), target]);
@haileys
haileys / gist:2340780
Created April 9, 2012 01:51 — forked from SamSaffron/gist:2340416
MiniProfiler API test
class Animal
def walk(distance, unit)
sleep 0.1
puts "walked #{distance} #{unit}"
end
end
class Dog < Animal
end
@haileys
haileys / best-haskell.hs
Created May 5, 2012 03:30 — forked from jacobh/pretty-python.py
OOPD 110 test 2
monthWeight m = do
putStr $ "input weight for month #" ++ show m ++ ": "
readLn
main = do
weights <- mapM monthWeight [1..12]
putStrLn $ "average weight is: " ++ (show $ sum weights `div` length weights)
@haileys
haileys / gist:2785862
Created May 25, 2012 05:03 — forked from jacobh/gist:2785812
Django ajax csrf coffeescript
document = cookie: "hello=world;this=that;what=which"
getCookie = (name) ->
if document.cookie
for [_, k, v] in (/^(.*?)=(.*)$/.exec kv for kv in document.cookie.split ";")
if k is name
return decodeURIComponent v
console.log getCookie "this"
@haileys
haileys / MIS.php
Created August 30, 2012 07:38 — forked from anonymous/MIS
<?php
require_once("../CoreSection/database.inc.php");
require_once("RequireFunctions.php");
function UpdateTimeStamp($TimeStamp, $TableName, $idCompany, $DatabaseObject)
{
$QueryCondition = "idCompany = " . $idCompany ." and TableName = " . $TableName;
$SelectStatus = $DatabaseObject->select("tablestimestamp", "TimeStamp", $QueryCondition);
/*
$Error = $DatabaseObject->getError();
if(isset($Error) && !empty($Error))//if(!$SelectStatus)
@haileys
haileys / sphinx.rb
Last active December 10, 2015 12:08 — forked from stefanoverna/sphinx.rb
require 'formula'
class Sphinx < Formula
url 'http://sphinxsearch.com/downloads/sphinx-0.9.9.tar.gz'
homepage 'http://www.sphinxsearch.com'
md5 '7b9b618cb9b378f949bb1b91ddcc4f54'
head 'http://sphinxsearch.googlecode.com/svn/trunk/'
fails_with_llvm "fails with: ld: rel32 out of range in _GetPrivateProfileString from /usr/lib/libodbc.a(SQLGetPrivateProfileString.o)"
@haileys
haileys / trololol.rb
Last active December 21, 2015 06:29 — forked from tenderlove/trololol.rb
module Kernel
def int(mid)
meth = instance_method(mid)
define_method(mid) { |*args, &bk|
val = meth.bind(self).call(*args, &bk)
raise TypeError, "#{mid} did not return an Integer" unless val.is_a? Integer
val
}
mid
end