Skip to content

Instantly share code, notes, and snippets.

View albertstill's full-sized avatar

Albert Still albertstill

View GitHub Profile
@albertstill
albertstill / node_pipe_example.js
Last active March 6, 2018 00:59
Node streaming html example. Theory is that the assets can be loaded in the browser while the Node server fetches data to render the body.
const http = require('http');
const server = http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
/*
below is cool because the browser could download assets while we fetch data,
BUT there is a huge web breaking caveat, it seems we have to know the HTTP response code at this
moment in time. But we don't - what if there is a 500 during fetching? what happens if we actually need to 404?
Defaulting to 200 would lead to undesirable outcomes, especially with web scrapers and APM tooling.
@albertstill
albertstill / deploy_staging_to_production.sh
Created January 21, 2016 09:29
Script that pushes a staging buckets data to a production bucket
# delete flag means files that exist in the prod bucket but not in the staging
# bucket are deleted during sync
aws s3 sync s3://staging.mybucket.com s3://mybucket.com --delete --region eu-west-1
@albertstill
albertstill / circle.yml
Created January 21, 2016 09:24
CircleCI parameterized build example
machine:
ruby:
version: 2.2.3
dependencies:
pre:
- sudo pip install awscli
# gets verion 1.15 instead of 1.13.4
- sudo apt-get update; sudo apt-get install wget
@albertstill
albertstill / deploy_to_staging.sh
Last active February 17, 2018 15:43
Build a static site from a Rails app using Wget and AWS S3
# precomile the static assets the HTML pages link to such as the .js, .css and .jpg files
RAILS_ENV=production bundle exec rake assets:precompile
# circleci has RAILS_ENV & RACK_ENV env variables set to test need to override. -d runs
# the server as a daemon.
RAILS_ENV=production RACK_ENV=production bundle exec rails s -d
# wait for server to load
sleep 10
@albertstill
albertstill / PostIndex.js
Last active August 4, 2020 00:53
Facebook Relay continuous scrolling example
class PostIndex extends React.Component {
state = { loading: false };
componentDidMount() {
window.onscroll = () => {
if (!this.state.loading
&& (window.innerHeight + window.scrollY)
>= document.body.offsetHeight) {
this.setState({loading: true}, () => {
import Post from './Post';
class App extends React.Component {
render() {
return (
<div>
<h1>Post list</h1>
<ul>
{this.props.posts.edges.map(edge =>
<Post key={edge.node.id} post={edge.node} />
query FetchInceptionQuery {
movie(title: "Inception") {
title
director
actors
released
type
plot
poster
director
query IntrospectionImdbNestedFieldsQuery {
__type(name: "Imdb") {
name
description
fields {
name
description
type {
name
kind
query IntrospectionMovieNestedFieldsQuery {
__type(name: "Movie") {
name
description
fields {
name
description
type {
name
kind
query IntrospectionQueryTypeQuery {
__schema {
queryType {
name
fields {
name
description
type {
name
kind