Skip to content

Instantly share code, notes, and snippets.

ptbrowne /
Created Jan 12, 2018
Predict requires according to variables used
#-*- 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)
#!/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 /
Created Oct 24, 2017
Horizontal bar chart with autolabel
# 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 /
Last active Oct 18, 2017
Shortcut to Chrome Inspect

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 /
Last active Sep 20, 2017
Replace several strings from file

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

Example :


  {"category": "personalCare"},
  {"category": "atm"},
ptbrowne /
Last active Aug 28, 2017

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

1. Output all translation strings

python en.json output

2. Copy those strings into Google Translate

ptbrowne /
Last active Aug 28, 2017
Removing css module from a repository

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 / App.js
Created May 29, 2017
standard test
View App.js
const App = function () {
return <div>Hello World !</div>
export default App
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, options)
const onSuccess = function (docs, response) {
View index.html
<!DOCTYPE html>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script src=''></script>
<script src=''></script>
<script src=''></script>
<link rel="stylesheet" href="" />
You can’t perform that action at this time.