Skip to content

Instantly share code, notes, and snippets.

@ptbrowne
ptbrowne / predict-requires.py
Created Jan 12, 2018
Predict requires according to variables used
View predict-requires.py
#-*- coding: utf-8 -*-
import fnmatch
import os
def glob(dir, pattern):
for root, dirnames, filenames in os.walk(dir):
for filename in fnmatch.filter(filenames, pattern):
yield os.path.join(root, filename)
View PA2.py
#!/usr/bin/env python
#-*- coding:utf-8 -*-
# #Natural Language Processing in Python
# #Assignment #2
# Exercises: 4, 8, 12, 13, 18, 25, 26 (Chapter 2)
# Your Turn: Pages 44, 55
from __future__ import division
from PA1 import count_initial_indent, strip_initial_indent, write_doc
@ptbrowne
ptbrowne / horizontal-bar-chart.py
Created Oct 24, 2017
Horizontal bar chart with autolabel
View horizontal-bar-chart.py
# a stacked bar plot with errorbars
%config InlineBackend.figure_format = 'retina'
import pandas as pd
from random import random
import matplotlib.pyplot as plt
def autolabel(rects):
"""
Attach a text label above each bar displaying its height
@ptbrowne
ptbrowne / shortcut-chrome-inspect.md
Last active Oct 18, 2017
Shortcut to Chrome Inspect
View shortcut-chrome-inspect.md

Chrome has made the path to inspect devices more and more difficult. Now to open the inspect devices tab, as of April 2016 it's Menu > More Devices > Developer Tools > Menu > More Tools > Inspect Devices.

Fortunately there is an easy solution : we can use customize the search engine functionality to add a shortcut via the search bar.

  1. Right click on the search bar, click 'Edit Search Engines'.
  2. At the end of the list you can add a search engine. Name it chrome inspect with the keyword insp and URL : chrome://inspect/#devices.
@ptbrowne
ptbrowne / readme.md
Last active Sep 20, 2017
Replace several strings from file
View readme.md

You have a file where you want to replace several strings.

Example :

file.json

[
  {"category": "personalCare"},
  {"category": "atm"},
@ptbrowne
ptbrowne / README.md
Last active Aug 28, 2017
easy_i18n.py
View README.md

You have a translation file full of English. You want to translate it to French easily.

1. Output all translation strings

python easy_i18n.py en.json output

2. Copy those strings into Google Translate

@ptbrowne
ptbrowne / README.md
Last active Aug 28, 2017
Removing css module from a repository
View README.md

To remove CSS modules from a repository, these steps can help.

codemod --extension 'jsx' 'styles\[(.*?)\]' '\1' # className={styles['a]} -> className={'a'}
find . | grep '.jsx$' | xargs jscodeshift --parser babel -t simpleClassNames.js # className={classNames('a', 'b', 'c')} -> className='a b c'

Check well, adjust manually and you are good to go.

@ptbrowne
ptbrowne / App.js
Created May 29, 2017
standard test
View App.js
const App = function () {
return <div>Hello World !</div>
}
export default App
@ptbrowne
ptbrowne / queryAll.js
Created May 12, 2017
queryAll for cozy client
View queryAll.js
const queryAll = function (cozyClient, mangoIndex, options) {
return new Promise((resolve, reject) => {
const documents = []
const fetch = function () {
return cozyClient.data.query(mangoIndex, options)
.then(onSuccess)
.catch(reject)
}
const onSuccess = function (docs, response) {
debugger
View index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.4.1/jasmine.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.4.1/jasmine-html.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.4.1/boot.min.js'></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.4.1/jasmine.css" />
You can’t perform that action at this time.