Skip to content

Instantly share code, notes, and snippets.

View slpsys's full-sized avatar
💭
💯

Marc Bollinger slpsys

💭
💯
View GitHub Profile
@slpsys
slpsys / map-lambda-reduce.py
Created December 14, 2010 02:33
A magical journey through bullshit.
>>> weight
10
>>> a
[1, 2, 3]
# ok, we have a nice list here. let's apply a map() to see if we can raise the power of all values:
>>> map((lambda x: x**2), a)
[1, 4, 9]
public static class StatsTools
{
private static double StdDevInternal<T>(this IEnumerable<T> Self, Func<T, double> Selector, Func<double, long, double> FinalStep)
{
double ret = 0.0, mean = 0.0;
long n;
mean = Self.Mean(Selector, out n);
foreach (var item in Self)
@slpsys
slpsys / mappings.cs
Created March 10, 2011 02:57
Mapping goofy shit with AutoMapper
Mapper.CreateMap<CacheObjects.CreditDefaultSwapPrice, CDSSettlementData>()
.ForMember(dest => dest.ProductKey, opt => opt.MapFrom(src => src))
.ForMember(dest => dest.Settlements, opt => opt.MapFrom(src => src.Settlements))
.AfterMap((src, dest) =>
{
if (dest.Settlements != null)
{
foreach (var settlement in dest.Settlements)
{
settlement.OpenInterest = src.OpenInterest;
@slpsys
slpsys / Argh.cs
Created March 16, 2011 00:24
Stupid Tamir.SharpSsh
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tamir.SharpSsh;
using Tamir.SharpSsh.jsch;
namespace FileService
{
/// <summary>
@slpsys
slpsys / this-seriously-does-not-work.php
Created March 28, 2011 21:38
Yet Another Reason Why PHP is Terrible, and Tooling Does Matter.
<?php
class Test {
public function What() { echo "What?"; }
}
// Fine
$a = new Test();
$a->What();
// This breaks
var dict = new Dictionary<int, int>() { {1, 1}, {2, 2}, {3, 3}};
var list = from record in dict.Keys
where record > 1
select record;
foreach (var item in list)
{
dict.Remove(item);
}
@slpsys
slpsys / Fuuuuuu-
Created April 22, 2011 00:43
fuuuuuuu-mysql.sql
-- This is T-SQL (SQL Server). This demonstrates two things MySQL can't do that I just ran into.
DECLARE @a TABLE
(
id int
)
DECLARE @b TABLE
(
id int,
name nvarchar(10),
fid int
public static DateTime today = DateTime.Today,
yesterday = today.AddDays(-1),
twoDaysAgo = yesterday.AddDays(-1),
threeDaysAgo = twoDaysAgo.AddDays(-1),
tomorrow = today.AddDays(1),
dayAfterTomorrow = tomorrow.AddDays(1),
twoDaysAfterTomorrow = dayAfterTomorrow.AddDays(1),
friday = today.AddDays((5 + 7 - (int)today.DayOfWeek) % 7), // http://www.imdb.com/title/tt0113118/
nextFriday = friday.AddDays(7), // http://www.imdb.com/title/tt0195945/
fridayAfterNext = friday.AddDays(7); // http://www.imdb.com/title/tt0293815/
@slpsys
slpsys / xignite-savon.rb
Created May 3, 2011 23:52 — forked from stw/gist:953289
Soap service test
#!/usr/bin/env ruby
require 'rubygems'
require 'savon'
require 'pp'
url = "http://www.xignite.com/xFinancials.asmx?WSDL"
client = Savon::Client.new(url)
response = client.request :get_other_ratios do
class Stuff:
dict = {}
def __getattr__(self, key):
if not key:
return self
elif self.dict.has_key(key):
return self.dict[key]
raise AttributeError,key
def __setitem__(self, key, value):