Skip to content

Instantly share code, notes, and snippets.

View scmx's full-sized avatar

Albert Arvidsson scmx

View GitHub Profile
@scmx
scmx / gist:0985b2d8a85314a10d26
Created March 4, 2015 11:36
Is the internet on fire? OSX Notification

Have you seen the excellent https://istheinternetonfire.com/ website?

They provide a nice dns txt api that I decided to use the give myself an OSX notification whenever they update.

img

Save the following to a file somewhere in your $PATH. I chose .bin/istheinternetonfire

#!/usr/bin/env bash
@scmx
scmx / gist:cf471c13333712c789d9
Last active August 29, 2015 14:18
Migrate old paperclip folders into the newer id_partition structure #rails #paperclip #id_partition #migrate

The version below is specifically tailored to handle a model named Item where the attachment is called image.

#!/usr/bin/env ruby

require "fileutils"

if File.directory? "public/system/items/images"
  puts "Nothing to do, you've already done this"
  exit 0
@scmx
scmx / Gemfile
Last active August 29, 2015 14:19
Roundcube merge two separate intersecting databases #roundcube #mysql #contacts #merge #ruby #activerecord
source "https://rubygems.org"
gem 'mysql2'
gem 'activerecord'
gem 'safe_attributes'
@scmx
scmx / gist:b07361dd3071669320a7
Last active January 7, 2016 18:03
Adding a new ruby version to a server with rbenv
ssh deploy@some-server
# Upgrade ruby-build (So it knows about the new ruby version and so can fetch it for us)
cd ~/.rbenv/plugins/ruby-build
git pull
# Grab a coffee while downloading ruby
rbenv install 2.2.4
# Make sure bundle command is available
@scmx
scmx / immutable-delete.js
Last active March 28, 2017 10:13
While writing a redux reducer I ran into the issue that I wanted to remove a property from an object without mutating it. Here's how I solved it. tl;dr Just use http://devdocs.io/lodash/index#omit #redux #reducers #immutability
import test from 'ava'
import deepFreeze from 'deep-freeze'
import omit from 'lodash/omit'
test('normal delete will mutate the object', t => {
const obj = { a: 1, b: 2 }
deepFreeze(obj)
t.throws(() => delete obj.a)
})
@scmx
scmx / react-proptype-warnings-as-errors-with-sinon.markdown
Last active March 1, 2019 08:42
Make React PropType warnings throw errors with mocha.js, enzyme.js and sinon.js

Make React PropType warnings throw errors with enzyme.js + sinon.js + mocha.js

A simple stateless functional component that we want to test that it renders without propType warnings.

import React, { PropTypes } from 'react'

let VersionListItem = function ({ active, version }) {
  return (
@scmx
scmx / ctrl-to-stay-on-homerow.md
Last active September 26, 2017 09:12
Using <Ctrl> to stay on the home row in your terminal and vim #terminal #vim #osx #unix

Here are some tricks you can use to be able to stay on the home row (asdfghjkl etc) when you're in a terminal or in vim.

Terminal

  • <Ctrl>+l Clear the terminal
  • <Ctrl>+a go to beginning of line
  • <Ctrl>+e go to end of line
  • <Ctrl>+p instead of <Up>, to see previous command
  • <Ctrl>+n instead of <Down>, to see next command
  • <Ctrl>+k + <Ctrl>+u Cut current command
  • +y Paste command
@scmx
scmx / docker-prompt.md
Last active January 19, 2024 21:36
How to get a fancier bash prompt PS1 inside a docker container #docker #ps1 #emoji

How to get a fancier bash prompt PS1 inside a docker container

Today I wanted to make a recording of me running some commands inside a docker-container.

❯ docker-compose run app bash
root@e9bb2af4dc11:/usr/local/go/src/example.com/dev/project#

Needless to say it looked a bit bland with no colors and a long prompt that prevents me from recording a small terminal and show the full commands I'm

@scmx
scmx / vscode-getting-up-to-speed.md
Last active November 6, 2019 08:33
VSCode Getting up to speed. #vscode Here are some extensions I found essential with when switching from #vim

Getting up to speed with Visual Studio Code

To open the command prompt <Cmd> + <Shift + p. Or use <Cmd> + p and type >

Open the command prompt and type >Extensions: Install Extensions, there you can search for and install the extensions below.

[rewrap][rewrap] Wrapping long lines at 80 columns

As a vim:er I'm used to selecting a few lines with V and then pressing gq to wrap them. Very handy for markdown files, git commit body etc.

@scmx
scmx / ghpr.md
Last active July 1, 2017 10:56
Bash function for checking out a github pull request branch #git #github #pull-request #bash

Are you having trouble checking out someone's pullrequest from a terminal?

Example usage

git clone git@github.com:example/example.git
ghpr someuser:somebranch # Copy this from the PR

It does these things

  • Adds someuser as a git remote