Skip to content

Instantly share code, notes, and snippets.

@np-8
np-8 / LICENCE.md
Last active Nov 24, 2022
Find all zeroes (roots) of a function with python (1d)
View LICENCE.md

Copyright 2020 Niko Pasanen

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHE

@np-8
np-8 / send_email_with_gmail.py
Last active Aug 4, 2020
Sending emails with python and Gmail
View send_email_with_gmail.py
import smtplib
from_address = 'no-reply@example.com'
username = 'my.email@gmail.com'
password = 'password'
def send_email(to_address, subject, message):
email_string = """\
From: {from_address}
@np-8
np-8 / generate_password.py
Last active Aug 4, 2020
generate passwords with python
View generate_password.py
import secrets
password = secrets.token_urlsafe(75)
# Example: Hk0ba0AKkN_ZAh2CCIuMj87HGfL8EJfkCh0ADZHfi1nwLuyxFjSTsw_kluINjNjmPjGFzBXpkPyvs0Y9GGNpPiG8RcByFPyT5DGS
@np-8
np-8 / jslingui-package.js
Last active Dec 17, 2017
jslingui-B-package.json
View jslingui-package.js
// package.json
{
...
"dependencies": {
...
"lingui-react": "^1.4.1",
...
},
"lingui": {
"format": "minimal",
@np-8
np-8 / minimal-trans-exampl3.jsx
Created Dec 16, 2017
Minimal Translated React Component v3
View minimal-trans-exampl3.jsx
// TestI18n.jsx
import React from 'react'
import { Trans } from 'lingui-react'
const Testi18n = () => {
return <Trans>This is a test</Trans>
}
export default Testi18n
@np-8
np-8 / index.jsx
Created Dec 16, 2017
jsLingui example index.jsx
View index.jsx
// index.jsx
import { I18nProvider } from 'lingui-react'
import { unpackCatalog } from 'lingui-i18n'
import catalog from '../locale/fi_FI/messages.js'
const catalogs = { fi_FI: unpackCatalog(catalog) }
import App from './scenes/App'
render(
View Testi18n.jsx
// Testi18n.jsx
import React from 'react'
import { Trans } from 'lingui-react'
import PropTypes from 'prop-types'
const Testi18n = (props, context) => {
console.log('props:', props)
console.log('context:', context)
return <Trans>This is a test</Trans>
}
@np-8
np-8 / I18nProvider.js
Created Dec 16, 2017
I18nProvider childContextTypes
View I18nProvider.js
I18nProvider.childContextTypes = {
linguiPublisher: PropTypes.object.isRequired,
linguiDefaultRender: PropTypes.any
};
@np-8
np-8 / messages.js
Created Dec 15, 2017
jslingui en_US messages.js unminified
View messages.js
// locale/en_US/messages.js
module.exports = {
l: {
p: function(n, ord) {
var s = String(n).split('.'),
v0 = !s[1],
t0 = Number(s[0]) == n,
n10 = t0 && s[0].slice(-1),
n100 = t0 && s[0].slice(-2)
if (ord)
@np-8
np-8 / messages.js
Last active Dec 15, 2017
jslingui fi_FI messages.js unminified
View messages.js
// locale/fi_FI/messages.js
module.exports = {
l: {
p: function(n, ord) {
var s = String(n).split('.'),
v0 = !s[1]
if (ord) return 'other'
return n == 1 && v0 ? 'one' : 'other'
}
},