Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
💯

Marc Bollinger slpsys

💭
💯
View GitHub Profile
@slpsys
slpsys / 0_reuse_code.js
Last active Aug 29, 2015
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
View redshift_size_by_table.sql
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 Aug 12, 2015
Generating ASTs in JISON
View addition_grammar.y
/* lexical grammar */
%lex
%%
\s+ /* skip whitespace */
[0-9]+("."[0-9]+)?\b return 'NUMBER'
"+" return '+'
<<EOF>> return 'EOF'
. return 'INVALID'
View 1_views.sql
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 Dec 14, 2010
A magical journey through bullshit.
View map-lambda-reduce.py
>>> 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]
View prob_utilities.cs
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 Mar 10, 2011
Mapping goofy shit with AutoMapper
View mappings.cs
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 Mar 16, 2011
Stupid Tamir.SharpSsh
View Argh.cs
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 Mar 28, 2011
Yet Another Reason Why PHP is Terrible, and Tooling Does Matter.
View this-seriously-does-not-work.php
<?php
class Test {
public function What() { echo "What?"; }
}
// Fine
$a = new Test();
$a->What();
// This breaks
View IteratorBlockGotcha.cs
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);
}
You can’t perform that action at this time.