Skip to content

Instantly share code, notes, and snippets.

View behnood-eghbali's full-sized avatar
🎯
Focusing

Behnood Eghbali behnood-eghbali

🎯
Focusing
View GitHub Profile
@behnood-eghbali
behnood-eghbali / read-logs.py
Created September 2, 2020 13:34
reading npm log files from terminal using python (linux)
# reading npm log files from terminal using python (linux)
import os, glob, sys
log_path = os.path.expanduser('~/.npm/_logs/*.log')
log_files = glob.glob(log_path)
for file in log_files:
f = open(file)
sys.stdout.write(f.read())
f.close()
@behnood-eghbali
behnood-eghbali / read-logs.go
Last active September 2, 2020 13:35
reading npm log files from terminal using golang (linux)
package main
import (
"fmt"
"os"
)
func main() {
os.Chdir("~/.npm/_logs")
file, err := os.Open("2020-04-20T09_38_57_076Z-debug.log")
@behnood-eghbali
behnood-eghbali / multidict.py
Created April 25, 2020 15:09
Mapping Keys to Multiple Values in a Dictionary (Python)
# Mapping Keys to Multiple Values in a Dictionary with defaultdict (multidict)
# A dictionary is a mapping where each key is mapped to a single value. If you want to
# map keys to multiple values, you need to store the multiple values in another container
# such as a list or set.
from collections import defaultdict
first_dict = {'a': 1, 'b': 2, 'c': 3}
second_dict = defaultdict(list)
for key in first_dict:
@behnood-eghbali
behnood-eghbali / multiple-delimiters.py
Last active March 16, 2020 16:08
Splitting Strings on Any of Multiple Delimiters in Python
text = "Python's built-in interfaces to operating-system services make it ideal for writing portable, maintainable system-administration tools and utilities (sometimes called shell tools)."
import re
fields = re.split(r'[;,.()?!\s]\s*', text)
fields = filter(None, fields)
print(fields)
#["Python's", 'built-in', 'interfaces', 'to', 'operating-system', 'services', 'make', 'it', 'ideal', 'for', 'writing', 'portable', 'maintainable', 'system-administration', 'tools', 'and', 'utilities', 'sometimes', 'called', 'shell', 'tools']
@behnood-eghbali
behnood-eghbali / AddTodo.js
Last active December 4, 2019 09:34
Simple Todo App Using React Context API & Material-UI
import React, { Component } from 'react';
import Paper from '@material-ui/core/Paper';
import Grid from '@material-ui/core/Grid';
import TextField from '@material-ui/core/TextField';
import InputAdornment from '@material-ui/core/InputAdornment';
import AddCircleRoundedIcon from '@material-ui/icons/AddCircleRounded';
import {TodoContext} from './TodoContext';
export default class AddTodo extends Component {
static contextType = TodoContext;
@behnood-eghbali
behnood-eghbali / App.js
Last active November 8, 2019 18:40
Simple Example of React Context API
import React, { Component } from 'react'
import Toolbar from './Toolbar'
import {ThemeContext, themes} from './ThemeContext'
export default class App extends Component {
constructor(props) {
super(props)
this.state = {theme: themes.light}
this.toggleTheme = this.toggleTheme.bind(this)
@behnood-eghbali
behnood-eghbali / App.js
Created October 27, 2019 01:07
Render Props vs Component Composition (React)
import React from 'react';
import './App.css';
import MyFunctionComponent from './MyFunctionComponent';
import MyClassComponent from './MyClassComponent';
import MyAnotherClassComponent from './MyAnotherClassComponent';
function App() {
return (
<div className="App">
<MyFunctionComponent />
@behnood-eghbali
behnood-eghbali / BlogPost.js
Created October 26, 2019 23:31
Simple Implementation of Form Inputs Using HOCs (React)
import React, { Component } from 'react';
//import TextBlock from './TextBlock';
import {BlogPostWithSubscription} from './withSubscription';
class BlogPost extends Component {
render() {
const {post, handlePostChange, handlePostSubmit} = this.props;
return (
<div className="MyApp">
interface Iterator<T> {
next(value?: any): IteratorResult<T>;
return?(value?: any): IteratorResult<T>;
throw?(e?: any): IteratorResult<T>;
}
interface IteratorResult<T> {
done: boolean;
value?: T;
}
@behnood-eghbali
behnood-eghbali / Get.js
Created August 30, 2019 06:25
Implementing HTTP methods (GET & POST) with json-server and React
import React, { Component } from 'react';
import './App.css';
export default class Get extends Component {
constructor(props) {
super(props);
this.state = {
error: null,
isLoaded: false,