Skip to content

Instantly share code, notes, and snippets.

@nicnocquee
nicnocquee / next.config.js
Created May 5, 2020 15:41
Small function to expose environment variables to nextjs app
require('dotenv').config()
const getEnvWithPrefixes = (prefixes = ['REACT_APP_', 'FIREBASE_']) => {
return Object.keys(process.env).reduce((prev, curr) => {
if (prefixes.some(p => curr.startsWith(p))) {
return {
...prev,
[curr]: process.env[curr],
}
}
@nicnocquee
nicnocquee / uicollectionview-playground.playyground
Created October 19, 2018 06:37
Testing UICollectionView in Swift Playground iPad
import UIKit
import PlaygroundSupport
let cellSize = CGSize(width: 100, height: 100)
class Cell: UICollectionViewCell {
var imageView: UIImageView?
var identifier: String?
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
@nicnocquee
nicnocquee / my_alias.sh
Last active April 24, 2017 06:51
my shell alias
# Color LS
colorflag="-G"
alias ls="command ls ${colorflag}"
alias l="ls -lF ${colorflag}" # all files, in long format
alias la="ls -laF ${colorflag}" # all files inc dotfiles, in long format
alias lsd='ls -lF ${colorflag} | grep "^d"' # only directories
alias lsa="command ls -la | lolcat"
# Quicker navigation
alias ..="cd .."
@nicnocquee
nicnocquee / swift_closure_dont_understand.swift
Created March 17, 2017 14:17
Why is this not creating strong reference cycles?
class HTMLElement {
let name: String
let text: String?
lazy var asHTML: () -> String = {
[unowned self] in // without this capture list, self is captured strongly in the closure
if let text = self.text {
return "<\(self.name)>\(text)</\(self.name)>"
} else {
return "<\(self.name) />"
}
@nicnocquee
nicnocquee / mount_ssh.sh
Last active March 1, 2017 13:22
command to mount ssh
#!/bin/sh
# need to install fuse and sshfs first https://osxfuse.github.io
sshfs user@host: /mountpath -o allow_other,defer_permissions,IdentityFile=~/.ssh/id_rsa
@nicnocquee
nicnocquee / resolve_keypath.js
Last active May 3, 2017 20:56
JS function to resolve key path for Immutable.js
// @flow
import Immutable from 'immutable'
export const resolveKeyPaths = (source: Immutable.Collection, keypaths: Array<any>) => {
const isFunction = (obj: any) => {
return !!(obj && obj.constructor && obj.call && obj.apply);
};
var resolvedKeyPaths = []
@nicnocquee
nicnocquee / reboot_simulator.sh
Created July 9, 2016 20:01
Boot or reboot iOS simulator
#!/bin/bash
BOOTING="Booting "
if [ $# -eq 0 ]
then
SIMULATOR=$(xcrun simctl list | grep Booted | cut -d$'\n' -f1 | cut -d "(" -f2 | cut -d ")" -f1)
if [ ! -z "$SIMULATOR" ]; then
SIMULATORNAME=$(xcrun instruments -s | grep $SIMULATOR | cut -d "[" -f1)
BOOTING="Rebooting $SIMULATORNAME"
fi
@nicnocquee
nicnocquee / open simulator.sh
Created July 9, 2016 18:52
Script to open simulator specify device and iOS
open /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app --args -CurrentDeviceUDID `xcrun instruments -s | grep "iPhone 6s Plus (9.3)" | grep -v "Apple Watch" | cut -d "[" -f2 | cut -d "]" -f1`
@nicnocquee
nicnocquee / 0_reuse_code.js
Created May 23, 2016 22:15
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@nicnocquee
nicnocquee / convert_video_to_gif.sh
Created February 25, 2016 21:01
Convert video to GIF
#!/bin/sh
palette="palette.png"
filters="fps=10,scale=320:-1:flags=lanczos"
ffmpeg -v warning -i $1 -vf "$filters,palettegen" -y $palette
ffmpeg -v warning -i $1 -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse" -y $1.gif
rm -f $palette