Skip to content

Instantly share code, notes, and snippets.

@dstarh
dstarh / smtpd.py
Created December 21, 2012 14:06
python simple debugging smtp server
import smtpd
import asyncore
server = smtpd.DebuggingServer(('127.0.0.1', 1025), None)
asyncore.loop()
@dstarh
dstarh / gist:4525095
Last active December 11, 2015 01:39
class heirarchy
module X
def initialize(params ={})
puts 'setting params in module x'
@foo = params[:foo]
end
end
module Y
def initialize(params ={})
super if defined?(super)
puts 'setting params in module y'
#foo
#bar
#baz
renders
<div id="foo">
<div id="bar">
<div id="baz">
</div>
#/bin/sh
echo -e "\033]50;SetProfile=$1\a"
/usr/bin/ssh $*
echo -e "\033]50;SetProfile=Default\a"
string pattern = @"[^ -~]";
string input = THE XML STRING
string replacement = "";
Regex rgx = new Regex(pattern);
string result = rgx.Replace(input, replacement);
Console.WriteLine("Original String: '{0}'", input);
Console.WriteLine("Replacement String: '{0}'", result);
foo
-------
foo_id
name
foo_hierarchy
-------
foo_child_id
foo_parent_id
id
dstarh:danger-danger-squared.local in [/usr/local/site/tools] rm -rf ~/.grails
dstarh:danger-danger-squared.local in [/usr/local/site/tools] |NUT-37-grails-2.1.4-java-7 ✗|$ grails install-plugin sublog --stacktrace
| Installed plugin sublog-0.5.3
| Error Error executing script InstallPlugin: BUG! exception in phase 'conversion' in source unit 'Script1.groovy' No such property: importPackages for class: org.codehaus.groovy.ast.ModuleNode (NOTE: Stack trace has been filtered. Use --verbose to see entire trace.)
BUG! exception in phase 'conversion' in source unit 'Script1.groovy' No such property: importPackages for class: org.codehaus.groovy.ast.ModuleNode
at org.codehaus.gant.IncludeTargets.leftShift(IncludeTargets.groovy:72)
at org.codehaus.gant.IncludeTargets$leftShift$0.call(Unknown Source)
at InstallPlugin$_run_closure8.doCall(InstallPlugin:246)
at InstallPlugin$_run_closure8.call(InstallPlugin)
at InstallPlugin$_run_closure14_closure29.doCall(InstallPlugin:337)
log4j = {
appenders {
console name:'stdout', layout:pattern(conversionPattern: '[%r] %c{2} %m%n')
if (tools.error.email.to && Globals.getProperties().SMTP_HOST) {
def patternLayout = new org.apache.log4j.PatternLayout()
patternLayout.setConversionPattern("[%r] %c{2} %m%n")
def mailAppender = new org.apache.log4j.net.SMTPAppender()
mailAppender.setFrom("errors@email.com")
mailAppender.setTo("${tools.error.email.to}")
mailAppender.setSubject("Grails Tools Application Error")
/* *******************************************
// LICENSE INFORMATION
// The code, "Detecting Smartphones Using PHP"
// by Anthony Hand, is licensed under a Creative Commons
// Attribution 3.0 United States License.
//
// Updated 01 March 2010 by Bryan J Swift
// - Remove un-needed if statements instead just returning the boolean
// inside the if clause
//
average = (50.0 + 75.0 + 90.0) / 3.0 => 71.66666666666667 (14 decimal places)
average = ratings.average(:rating).to_f => 71.6666666666667 (13 decimal places)
:rating is a double in postgres.