Skip to content

Instantly share code, notes, and snippets.

@fj
fj / gist:1597544
Created Jan 11, 2012
Slightly nicer way of writing large files to disk with PHP
View gist:1597544
// Copy big file from somewhere else
$src_filepath = 'http://example.com/all_the_things.txt'; $src = fopen($src_filepath, 'r');
$tmp_filepath = '...'; $tmp = fopen($tmp_filepath, 'w');
$buffer_size = 1024;
while (!feof($src)) {
$buffer = fread($src, $buffer_size); // Read big file/data source/etc. in small chunks
fwrite($tmp, $buffer); // Write in small chunks
}
@fj
fj / cf-api-pagination.sh
Created Sep 12, 2019
Paginate the CF API.
View cf-api-pagination.sh
#!/bin/bash
set -e
# requires `jq`
function load_all_pages {
URL="$1"
DATA=""
until [ "$URL" == "null" ]; do
RESP=$(cf curl "$URL")
DATA+=$(echo "$RESP" | jq .resources)
@fj
fj / pipeline-with-manual-intervention.yml
Created Jul 17, 2018
pipeline-with-manual-intervention.yml
View pipeline-with-manual-intervention.yml
---
resources:
- name: my-resource
type: git
source:
branch: master
uri: https://github.com/pivotalservices/concourse-pipeline-samples.git
jobs:
- name: Run-automatically
@fj
fj / tasks.json
Created Jul 8, 2018
This is roughly the implicit `tasks.json` that would have been generated by the `rls-vscode` extension to work around the issue raised in issue #359.
View tasks.json
{
// This is roughly the implicit `tasks.json` that would have been generated
// by the `rls-vscode` extension to work around the issue raised in issue #359.
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "cargo build",
"command": "cargo",
"args": [
@fj
fj / Gemfile
Last active May 5, 2018
a pairing interview for Recurse
View Gemfile
source "https://rubygems.org"
ruby "2.5.0"
gem "paint"
@fj
fj / gist:1337718
Created Nov 3, 2011
Cardinality of the reals and intervals in the reals
View gist:1337718

So, @deathbob and myself were discussing whether the real numbers have the same cardinality as any interval of the real numbers. That is, if you pick an interval (say [0,1]), is it true that the cardinality of that interval is the same as that of the entire set of real numbers? Here's a defense of that idea.

Theorem 1: Pick any two intervals of the real numbers R. Then their cardinality is the same.

Proof: Let an interval [s,t] (with s < t) be the set of all real numbers between s and t, inclusive. To prove that the cardinality is equal, we need to show that you can write a one-to-one correspondence between any two such intervals -- say, [s,t] and [u,v].

There are lots of ways to do this, but a simple way to do it is just to map them linearly. Let's say you have the two intervals [0,1] and [0,2]. Take any real number in [0,1] -- say, 0.781. Now double it. You have just mapped it to a real number in [0,2], and you can

View postgres-10.sql
-- full-text search in JSON/JSONB columns
CREATE INDEX transactions_fts ON transactions
USING gin (( to_tsvector('english', transactions) ))
-- parallelism now supported or improved in:
-- * bitmap heap scans
-- * merge joins
-- * btree index scans
-- partitioning
View gist:8243261
# In a context somewhere, we'd like to do this:
u = User.new
u.extend Passworded
# Unfortunately, this doesn't work:
module Passworded
include ActiveModel::Model # Can't do this because ActiveModel::Model wants to be included
# on classes, not modules.
@fj
fj / example-fragment.html
Created Jul 2, 2017
reference example of the not-particularly-semantic HTML currently in place
View example-fragment.html
<div class="measure--lg">
<div class="g">
<div class="g-r">
<section class="g-r-c-6-12 p1 mx1 home-list">
<div class="block">
<div class="list-meta-title">
recent entries
<a href="http://localhost:3000/entries/" class="list-meta-all" title="see all entries">see all</a>
</div>
<ul class="list">
@fj
fj / compare.rb
Created May 5, 2017
Compares two YAML files and shows which keys are "missing" and which keys are "extras"
View compare.rb
require 'yaml'
class Hash
def fully_qualified_keys
map { |k,v|
v.fully_qualified_keys.map{ |a| "#{k}.#{a}" } rescue k.to_s
}.flatten
end
end