Skip to content

Instantly share code, notes, and snippets.

View Foo.php
<?php
$user = User::whereToken($token)->first();
if (!$user) {
return ['message' => 'Sorry, no user found with that token.'];
}
return $user;
View 3dtouchfix.js
onMoveShouldSetPanResponder: (e, g) => {
if (g.dx === 0 || g.dy === 0) return false;
return true;
},
// Or if you like 1 liners:
onMoveShouldSetPanResponder: (e, g) => !(g.dx === 0 || g.dy === 0),
View gist:11d5435e7717159c22650a2711e2d6e6
static boot
static bootTraits
static clearBootedModels
static addGlobalScope
static hasGlobalScope
static getGlobalScope
static observe
static hydrate
static hydrateRaw
static create
View classes.js
// Bind in constructor
class BindInConstructor {
constructor() {
this.foo = this.foo.bind(this);
this.bar = this.bar.bind(this);
}
foo() {
this.bar();
}
@dhrrgn
dhrrgn / read_logs.sh
Last active Oct 28, 2016
Quick script to grab one or more log files (even gzipped ones) from multiple hosts at once.
View read_logs.sh
#!/usr/bin/env bash
hosts=(
# list the hosts to grab the logs from
host1.foo.com
host2.foo.com
)
remote_files=(
# list the log files to grab
View func.php
<?php
public function __call($method, $args) {
if (! $this->isConnected() || ! method_exists($this->pdo, $method)) {
throw new \BadMethodCallException("Method '$method' not found on ExtendedPdo");
}
return call_user_func_array([$this->pdo, $method], $args);
}
View example.js
var imageUrls = [/* image urls here */];
// The basic prefetch and forget.
imageUrls.map((url) => Image.prefetch(url));
// ------------- OR -------------
// Prefetch and replace image urls that fail to load with a default image URL
// Note: You could/should bundle the default image with the app so it doesn't
// need prefetched, and would load instantly.
View reduxModelHelpers.js
import { combineReducers } from 'redux';
/**
* Combine a set of ReduxModel reducers.
*
* @param array {models} An array of ReduxModel objects.
* @return function A combined redux reducer
*/
export function combineModelReducers(models) {
let reducers = {};
View ScrollView.js
import React, {
Component,
PropTypes,
} from 'react';
import {
ScrollView as RNScrollView,
View,
} from 'react-native';
View MyWebView.js
import React, { Component, PropTypes } from 'react';
import { WebView } from 'react-native';
import CookieManager from 'react-native-cookies';
export default class extends Component {
static propTypes = {
clearCookies: PropTypes.bool,
};
static defaultProps = {