Skip to content

Instantly share code, notes, and snippets.

View hadnazzar's full-sized avatar
:electron:
Force be with you.

Melih Yumak hadnazzar

:electron:
Force be with you.
View GitHub Profile
@hadnazzar
hadnazzar / gist:c9d3b81e95d53267bb7ca88d95959e27
Created August 15, 2018 08:30
Open server at any directory
# 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"
}
@hadnazzar
hadnazzar / javascript
Created September 13, 2018 11:10
Validate email Javascript function
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());
}
@hadnazzar
hadnazzar / gist:c5f9fc8822b83832716082bb92ddb7af
Created September 14, 2018 09:01
React dynamic className
className={`wrapper searchDiv ${this.state.something}`}
@hadnazzar
hadnazzar / gist:73f3ff0cd4594007f0dfb5541c9e8bc6
Created September 14, 2018 15:28
Vertical scroll on page
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.
@hadnazzar
hadnazzar / gist:487323a7ba0434c433b2c3b23695e500
Created September 17, 2018 08:58
Sticky element in react
---
jsx
---
componentDidMount() {
window.addEventListener('scroll', this.handleScroll);
}
componentWillUnmount() {
window.removeEventListener('scroll', this.handleScroll);
@hadnazzar
hadnazzar / gist:b494abdfa1e5465786f771651f3a4430
Created September 27, 2018 09:45
Zsh Right Prompt for show github differences (diff --shortstat) in terminal prompt
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
/* 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"}
function add(x) {
return function(y){
return x + y
}
}
add(5)(3) // 8
add(2)(5) // 7
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]
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
}