Skip to content

Instantly share code, notes, and snippets.

@jamesnocentini
jamesnocentini / example.bash
Last active October 29, 2018 05:03
Build & install Ruby gem from CLI
gem build docbookrx.gemspec
gem install docbookrx-1.0.0.dev.gem
@jamesnocentini
jamesnocentini / gist:1e89a36036f76f8e6274a6fd7ff8b88d
Created October 20, 2018 17:07
Autosave in Visual Studio Code
. Open actions prompt: `ctrl +shif
@jamesnocentini
jamesnocentini / instructions.adoc
Created October 14, 2018 08:07
macOS configure cursor repeat speed

TODO

@jamesnocentini
jamesnocentini / shortcuts.adoc
Created October 6, 2018 07:46
Custom WebStorm shortcuts

Custom Shortcuts

  1. Open selected directory in Terminal: cmd + shift + \

@jamesnocentini
jamesnocentini / example.swift
Created October 4, 2018 10:29
Singleton Pattern in Swift/Java
import CouchbaseLiteSwift
class DatabaseManager {
private static var privateSharedInstance: DatabaseManager?
var database: Database
let DB_NAME = "travel-sample"
@jamesnocentini
jamesnocentini / example.js
Created October 3, 2018 05:17
Focus a TextInput programmatically
export default class Row extends React.Component {
render() {
return (
<View>
<TextInput
onSubmitEditing={() => {
this.secondInput.focus();
}/>
<TextInput
ref={(input) => {
@jamesnocentini
jamesnocentini / example.swift
Created October 2, 2018 13:25
Lazily instantiate property in Swift (Database instance in this case)
lazy var database: Database = {
let path = Bundle.main.path(forResource: self.DB_NAME, ofType: "cblite2")!
if !Database.exists(withName: self.DB_NAME) {
do {
try Database.copy(fromPath: path, toDatabase: self.DB_NAME, withConfig: nil)
} catch {
fatalError("Could not copy database")
}
}
do {
@jamesnocentini
jamesnocentini / example.js
Created October 2, 2018 05:04
List View in React Native
import React from 'react';
import {
ListView,
StyleSheet,
Text,
TextInput,
View
} from 'react-native';
import Row from './Row';
@jamesnocentini
jamesnocentini / example.sh
Created October 1, 2018 17:52
If/elif/else in Bash
#!/usr/bin/env bash
OUTPUT_FILE=${1}
if [ "${1}" = "starter-project" ]; then
echo "starter"
elif [ "${1}" = "final-project" ]; then
echo "final"
else
echo "Error: the output file must be called starter-project or final-project"
fi
@jamesnocentini
jamesnocentini / example.java
Created October 1, 2018 17:35
Ask for overlay permission in API 23 or above
public class MainActivity extends SplashActivity {
public static int ACTION_MANAGE_OVERLAY_PERMISSION_REQUEST_CODE = 5469;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
checkPermission();
}