Skip to content

Instantly share code, notes, and snippets.

Avatar

Josh Clayton joshuaclayton

View GitHub Profile
View foo.diff
diff --git a/src/attributes.rs b/src/attributes.rs
index e1641b2..a03d803 100644
--- a/src/attributes.rs
+++ b/src/attributes.rs
@@ -38,7 +38,9 @@ fn evaluate_attribute_value_components<'a>(
.iter()
.map(|v| match v {
AttributeValueComponent::RawValue(value) => value.to_string(),
- AttributeValueComponent::InterpolatedValue(values) => context.interpret(values),
+ AttributeValueComponent::InterpolatedValue(values) => {
View time_series_fun.sql
WITH weeks AS (
SELECT generate_series('2008-12-29'::date, now(), '7 days'::interval)::date AS week
)
SELECT
j.id AS category_id,
weeks.week,
COALESCE(SUM(t.amount), 0) AS weekly_spend,
COALESCE(MIN(t.amount), 0) AS minimum_spend,
COALESCE(MAX(t.amount), 0) AS maximum_spend,
COUNT(t.amount) AS transaction_count,
@joshuaclayton
joshuaclayton / date_calculations.rs
Last active Aug 28, 2020
Grouping values by date
View date_calculations.rs
use chrono::prelude::*;
// weeks
pub fn beginning_of_week(date: &NaiveDate) -> Option<NaiveDate> {
if date.weekday() == Weekday::Sun {
Some(date.clone())
} else {
NaiveDate::from_isoywd_opt(date.iso_week().year(), date.iso_week().week(), Weekday::Sun)
.map(|d| d - chrono::Duration::weeks(1))
@joshuaclayton
joshuaclayton / hash_flattener.rb
Created Jul 5, 2018
Flatten deeply-nested hashes
View hash_flattener.rb
def recursive_flatten(input, keys = [], acc = {})
input.keys.each do |k|
result_key = keys + [k]
if input[k].is_a?(Hash)
recursive_flatten(input[k], keys + [k], acc)
elsif input[k].is_a?(Array) && input[k].any? {|v| v.is_a?(Hash) }
input[k].each_with_index do |array_value, index|
result_key_with_index = keys + [k, "[#{index}]"]
View foo.hs
module Time.DateConversions
(
T.Day
-- current day from system
, today
-- average
, averageDaysBetween
-- beginning of period
View README.md

This is a rough draft (which works!) handling file composition for vim-projectionist.

Each of the *.json files live in ~/.projections, and projections lives somewhere in your $PATH. This uses jq to combine multiple JSON files into one. With navigation.zsh, we hook into cding into a directory, run projections, and if there's a 0 exit code, overwrite the output to .projections.json, which vim-projectionist then uses.

I've updated my ~/.gitignore to ignore .projections.json, so I'm not concerned about things messing up git.

View -
--langdef=coffee
--langmap=coffee:.coffee
--regex-coffee=/(^|=[ \t])*class ([A-Za-z]+\.)*([A-Za-z]+)( extends [A-Za-z_.]+)?$/\3/c,class/
--regex-coffee=/^[ \t]*(module\.)?(exports\.)?@?([A-Za-z_.]+):.*[-=]>.*$/\3/m,method/
--regex-coffee=/^[ \t]*(module\.)?(exports\.)?([A-Za-z_.]+)[ \t]+=.*[-=]>.*$/\3/f,function/
--regex-coffee=/^[ \t]*([A-Za-z_.]+)[ \t]+=[^->\n]*$/\1/v,variable/
--regex-coffee=/^[ \t]*@([A-Za-z_.]+)[ \t]+=[^->\n]*$/\1/f,field/
--regex-coffee=/^[ \t]*@([A-Za-z_.]+):[^->\n]*$/\1/f,static field/
--regex-coffee=/^[ \t]*([A-Za-z_.]+):[^->\n]*$/\1/f,field/
View BenchGroupBy.hs
-- ghc -O --make BenchGroupBy.hs && ./BenchGroupBy --output bench_group.html&& open bench_group.html
import Criterion.Main
import Control.Arrow ((&&&))
import qualified Data.List as L
import Data.Function
main = defaultMain [
bgroup "group" [ bench "old" $ nf oldGroupBy numbers
, bench "new" $ nf newGroupBy numbers
]
View BenchStringToInt.hs
-- ghc -O --make BenchStringToInt.hs && ./BenchStringToInt --output bench_string_to_int.html&& open bench_string_to_int.html
import Criterion.Main
import Data.Maybe (fromMaybe)
import Text.Parsec (parse)
import Text.Parsec.Token (makeTokenParser, integer)
import Text.Parsec.Language (haskellStyle)
import Data.Char (digitToInt, isDigit)
main = defaultMain [
@joshuaclayton
joshuaclayton / 0_reuse_code.js
Created Sep 22, 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
You can’t perform that action at this time.