This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Start an HTTP server from a directory, optionally specifying the port | |
function server() { | |
local port="${1:-8000}" | |
open "http://localhost:${port}/" && python -m SimpleHTTPServer "$port" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
validateEmail = (email) => { | |
const re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; | |
return re.test(String(email).toLowerCase()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
className={`wrapper searchDiv ${this.state.something}`} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.requestAnimationFrame(function step(timestamp) { | |
if (!start) start = timestamp; | |
// Elapsed milliseconds since start of scrolling. | |
let time = timestamp - start; | |
// Get percent of completion in range [0, 1]. | |
let percent = Math.min(time / duration, 1); | |
window.scrollTo(0, startingY + diff * percent); | |
// Proceed with animation as long as we wanted it to. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
jsx | |
--- | |
componentDidMount() { | |
window.addEventListener('scroll', this.handleScroll); | |
} | |
componentWillUnmount() { | |
window.removeEventListener('scroll', this.handleScroll); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git_prompt() { | |
#temp=`git symbolic-ref HEAD 2>/dev/null | cut -d / -f 3` | |
temp=`git diff --shortstat | sed -e 's/insertions//' -e's/deletions//'` | |
if [ "$temp" != "" ]; then | |
RPROMPT='%{$fg_no_bold[green]%}git:($temp%)%{$reset_color%} %{$fg_no_bold[yellow]%}[%1~]%{$reset_color%} %t' | |
else | |
RPROMPT='%{$fg_no_bold[yellow]%}[%~]%{$reset_color%} %t' | |
fi | |
} | |
autoload -Uz add-zsh-hook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Here's an example that uses (some) ES6 Javascript semantics to filter an object array by another object array. */ | |
// x = full dataset | |
// y = filter dataset | |
let x = [ | |
{"val": 1, "text": "a"}, | |
{"val": 2, "text": "b"}, | |
{"val": 3, "text": "c"}, | |
{"val": 4, "text": "d"}, | |
{"val": 5, "text": "e"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function add(x) { | |
return function(y){ | |
return x + y | |
} | |
} | |
add(5)(3) // 8 | |
add(2)(5) // 7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var array1 = [1, 4, 9, 16]; | |
// pass a function to map | |
const map1 = array1.map(x => x * 2); | |
console.log(map1); | |
// expected output: Array [2, 8, 18, 32] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, {Component} from 'react'; | |
import {Platform, StyleSheet, Text, View, FlatList, PermissionsAndroid} from 'react-native'; | |
import Contacts from 'react-native-contacts'; | |
type Props = {}; | |
export default class App extends Component<Props> { | |
state={ | |
contacts: null | |
} |
OlderNewer