Skip to content

Instantly share code, notes, and snippets.

View albertstill's full-sized avatar

Albert Still albertstill

View GitHub Profile
@albertstill
albertstill / enigma_machine.rb
Last active February 25, 2021 18:46
Understand how the Enigma machine works with 30 lines of Ruby
Plugboard = Hash[*('A'..'Z').to_a.sample(20)]
Plugboard.merge!(Plugboard.invert)
Plugboard.default_proc = proc { |_, key| key }
def build_a_rotor
Hash[('A'..'Z').zip(('A'..'Z').to_a.shuffle)]
end
ROTOR_1, ROTOR_2, ROTOR_3 = build_a_rotor, build_a_rotor, build_a_rotor
query IntrospectionQueryTypeQuery {
__schema {
queryType {
name
fields {
name
description
type {
name
kind
query IntrospectionMovieNestedFieldsQuery {
__type(name: "Movie") {
name
description
fields {
name
description
type {
name
kind
query IntrospectionImdbNestedFieldsQuery {
__type(name: "Imdb") {
name
description
fields {
name
description
type {
name
kind
query FetchInceptionQuery {
movie(title: "Inception") {
title
director
actors
released
type
plot
poster
director
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} />
@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}, () => {
@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 / 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_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