Skip to content

Instantly share code, notes, and snippets.

View ptbrowne's full-sized avatar

Patrick Browne ptbrowne

View GitHub Profile
@ptbrowne
ptbrowne / readme.md
Last active September 20, 2017 15:01
Replace several strings from file

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

Example :

file.json

[
  {"category": "personalCare"},
  {"category": "atm"},
@ptbrowne
ptbrowne / README.md
Last active March 2, 2024 12:59
Automatically add emojis to your commits

To automatically add emojis to your commits, you can use the commit-msg hook.

$ git init
$ ln -s commit-msg-emoji .git/hooks/commit-msg
@ptbrowne
ptbrowne / README.md
Last active August 28, 2017 13:34
easy_i18n.py

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 August 28, 2017 10:03
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
ptbrowne / App.js
Created May 29, 2017 09:18
standard test
const App = function () {
return <div>Hello World !</div>
}
export default App
@ptbrowne
ptbrowne / queryAll.js
Created May 12, 2017 07:44
queryAll for cozy client
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
class LeafletJSONField(JSONField):
widget = LeafletWidget(width='100%', height='400px')
def process_formdata(self, valuelist):
if valuelist:
value = valuelist[0]
if not value:
self.data = None
return
try:
@ptbrowne
ptbrowne / make-gif.sh
Last active October 4, 2016 07:49
make-gif
#!/bin/sh
# Make a gif from a video using optimized palette
#
# Usage: make-gif video.mov video.gif 200
#
# Will output a gif with width 200px
# You can use iw in the width expression to have the width of the input
# video : iw*0.5 will make the gif half the size of the video (useful
# for Retina displays)
#
@ptbrowne
ptbrowne / csv-mail-filter.py
Created September 6, 2016 12:42
Parse mailFilters.xml from Gmail to CSV, only supports to and forwardTo
from collections import defaultdict
from xml.etree import cElementTree as ET
def etree_to_dict(t):
# remove namespace
if hasattr(t.tag, 'find'):
i = t.tag.find('}')
if i >= 0:
t.tag = t.tag[i+1:]
@ptbrowne
ptbrowne / webpack-dev-server-index.js
Created May 11, 2016 16:19
webpack-dev-server-client
var url = require('url');
var SockJS = require("sockjs-client");
var stripAnsi = require('strip-ansi');
var scriptElements = document.getElementsByTagName("script");
var scriptHost = scriptElements[scriptElements.length-1].getAttribute("src").replace(/\/[^\/]+$/, "");
// If this bundle is inlined, use the resource query to get the correct url.
// Else, get the url from the <script> this file was called with.
var urlParts;
if (typeof __resourceQuery === "string" && __resourceQuery) {