Skip to content

Instantly share code, notes, and snippets.

View johngrimes's full-sized avatar
🚴
coding and cycling

John Grimes johngrimes

🚴
coding and cycling
View GitHub Profile
@johngrimes
johngrimes / alter-owner.sql
Created May 21, 2014 02:23
Change the owner of all relations within a PostgreSQL database
SELECT exec('ALTER TABLE ' || quote_ident(s.nspname) || '.' || quote_ident(s.relname) || ' OWNER TO $NEWUSER')
FROM (SELECT nspname, relname
FROM pg_class c JOIN pg_namespace n ON (c.relnamespace = n.oid)
WHERE nspname NOT LIKE E'pg\\_%' AND
nspname <> 'information_schema' AND
relkind IN ('r','S','v') ORDER BY relkind = 'S'
) s;
def index
@areas = Area.all
@area = Area.find_by(slug: params[:area_slug]).presence || Area.find_by(slug: 'city')
conditions = { area: @area.subtree }
conditions.merge! params.select { |k,v|
[:bedrooms, :unit].include?(k) and !v.blank?
}
conditions[:property_type] = params[:type] || 'residential'

Keybase proof

I hereby claim:

  • I am johngrimes on github.
  • I am johngrimes (https://keybase.io/johngrimes) on keybase.
  • I have a public key ASDseF3pJf7VEc366sRqLX3DdERIL2ZHzukyn9IbeZOCDQo

To claim this, I am signing this object:

@johngrimes
johngrimes / generating-local-certs.md
Last active February 6, 2018 22:50
Generating a local CA and certificates

Generating a local CA and certificates

Create this file as [hostname].ext

authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage=digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName=@alt_names
@johngrimes
johngrimes / deregister-service-workers.md
Created February 7, 2018 21:53
De-register service workers

De-registers any service workers, if the browser supports service worker and if there are any present.

if (navigator.serviceWorker) {
  navigator.serviceWorker.getRegistrations().then(function(registrations) {
    for (let registration of registrations) {
      registration.unregister()
    }
  })
}
@johngrimes
johngrimes / formatStagedFiles.sh
Created February 14, 2018 22:15
Format staged files with Prettier before commit
#!/bin/bash
STAGED=$(git diff --name-only --cached --diff-filter=AM | egrep '^(.*).(js|json|css)$')
yarn prettier --write $STAGED
git add $STAGED
@johngrimes
johngrimes / Dockerfile
Created February 14, 2018 22:21
Injecting environment variables into config.json using Docker
FROM nginx
COPY docker/start.sh /
COPY docker/buildConfig.sh /
RUN chmod +x /start.sh /buildConfig.sh
COPY docker/myapp.nginx.conf /etc/nginx/conf.d/default.conf
COPY build /usr/share/nginx/html
ENV MYAPP_OPTION_A="Default option A value"
@johngrimes
johngrimes / nginx.conf
Created February 14, 2018 22:23
Ideal Nginx configuration for JavaScript single-page app
server {
listen 80;
root /usr/share/nginx/html;
gzip on;
gzip_types text/css application/javascript application/json image/svg+xml;
gzip_comp_level 9;
etag on;
location / {
try_files $uri $uri/ /index.html;
}
@johngrimes
johngrimes / recordRelease.sh
Created February 14, 2018 22:42
Recording releases with Sentry and Create React App
#!/bin/bash
VERSION=$(git rev-parse HEAD)
yarn run sentry-cli releases -p $SENTRY_PROJECT new $VERSION && \
yarn run sentry-cli releases -p $SENTRY_PROJECT set-commits --auto $VERSION && \
yarn run sentry-cli releases -p $SENTRY_PROJECT files $VERSION upload-sourcemaps --url-prefix https://$TARGET_HOSTNAME/static/js build/static/js && \
yarn run sentry-cli releases -p $SENTRY_PROJECT deploys $VERSION new --env $TARGET_HOSTNAME
@johngrimes
johngrimes / davmail-launchd.md
Last active February 22, 2018 00:52
Keep DavMail running with launchd

Keep DavMail running with launchd

Create the following file at ~/Library/LaunchAgents/net.sourceforge.davmail.agent.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
	<dict>
 Label