Skip to content

Instantly share code, notes, and snippets.

View slpsys's full-sized avatar
💭
💯

Marc Bollinger slpsys

💭
💯
View GitHub Profile
@slpsys
slpsys / 0_reuse_code.js
Last active August 29, 2015 14:12
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
select
cast(use2.usename as varchar(50)) as owner,
pgc.oid,
trim(pgdb.datname) as Database,
trim(pgn.nspname) as Schema,
trim(a.name) as Table,
(b.mbytes / 1024) gbytes,
a.rows,
((case when a.rows > 0 then b.mbytes / a.rows::real end) * 1024) kb_per_row,
round(b.mbytes / (sum(b.mbytes) over ())::real * 100, 4) pct_of_cluster
@slpsys
slpsys / addition_grammar.y
Created August 12, 2015 06:00
Generating ASTs in JISON
/* lexical grammar */
%lex
%%
\s+ /* skip whitespace */
[0-9]+("."[0-9]+)?\b return 'NUMBER'
"+" return '+'
<<EOF>> return 'EOF'
. return 'INVALID'
@slpsys
slpsys / 1_views.sql
Last active September 15, 2015 21:28
warehouse=# CREATE VIEW events.events AS SELECT * FROM events.a UNION SELECT * FROM events.b;
CREATE
warehouse=# CREATE VIEW events.events AS SELECT * FROM events.a UNION ALL SELECT * FROM events.b;
CREATE
@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);
}