Skip to content

Instantly share code, notes, and snippets.

@kof
kof / external-motivators.md
Last active July 3, 2017 17:43
External things that keep me motivated at work
  1. Open Source being officially part of the job, not just an "after job fun" instead of spending time with the family.
  2. Colleagues one can learn from, not those one needs to clean up after.
  3. Money matters. Only a stupid person can think that money doesn't matter in our capitalistic society. This also includes social security, medical ensurance and any other expenses. I am not mercantile, no.
  4. Soft deadlines. Having time to do things right.
  5. No pressure in being at time every day in the office. We all got our issues.
  6. Workout during working hours. Possibility to go quickly for a run or to the gym.
  7. Office is optional. I prefer to work from any location I want. Sometimes being in the office is nice though.
  8. Good sitting conditions: good chairs, gym ball, stay desk, sofas.
  9. Relaxation room or nap room.
@kof
kof / detect-rendered-css.js
Created May 28, 2017 22:00
Detect Rendered CSS using a probe container.
// This allows you to benchmark CSSinJS libs after styles have been really applied.
function detectCSSRendered(className, callback) {
const probe = document.createElement('div')
probe.style.visibility = 'hidden'
probe.className = className
var style = document.head.appendChild(document.createElement('style'))
style.textContent = '' +
'@keyframes probe-animation {' +
' from {left: 20%}' +
@kof
kof / StyledButton.js
Last active March 22, 2017 18:31
Styled Primitive Components with JSS
import {styled} from 'react-jss-components'
const RedButton = styled('button', {
color: 'red'
})
<RedButton>Click me</RedButton>
@kof
kof / MyComponent.js
Last active November 7, 2016 18:04
When to use functional components.
const Title = ({children}) => (
<div className={classes.titleContainer}>
<span className={classes.titleIcon} />
<h3 className={classes.titleHeadline}>
{children}
</h3>
</div>
)
@kof
kof / react-inline-styles.md
Last active April 5, 2016 11:36
React inline style rendering

Rendering a style update

  1. Unset previous props.

Iterate over lastStyle and copy keys into styleUpdates with empty string as a value in order to "unset" them when they are missing in the next style version.

  1. Find modified props.

Iterate over new style and copy modified keys only into styleUpdates.

/******************************************************************************
* Screens DPI
* @see
* http://developer.android.com/guide/webapps/overview.html
* http://developer.android.com/guide/practices/screens_support.html
*****************************************************************************/
/*mdpi*/
@media (-webkit-min-device-pixel-ratio : 1) and (min-width: 320px), (min-device-pixel-ratio : 1) and (min-width: 320px) {
body {zoom: 0.5 !important;}
var m = require('mongoose'),
fs = require('fs'),
http = require('http');
m.connect('mongodb://localhost/test');
var ObjectId = m.Types.ObjectId;
var UserModel = m.model('user', require('./userSchema', {strict: false}));
var data = { "birthday" : Date("1981-09-21T00:00:00Z"), "email" : "aaaaa@bbbbbb.com", "firstName" : "Hannes", "lastIpAddr" : "138.188.103.139", "lastName" : "Gassert", "likedSkim" : true, "locale" : "en_US", "nick" : "Hannes", "relationshipStatus" : "In a Relationship", "urlName" : "han", "coins" : 550, "marketValue" : 63, "currentLocale" : "en-us", "sports" : [ ], "schools" : [ { "id" : "109924452370813", "name" : "Gymnasium Leonhard", "_id" : ObjectId("517fc1e66d19040200004fb7") }, { "id" : "107967209224731", "name" : "University of Fribourg", "_id" : ObjectId("517fc1e66d19040200004fb6") }, { "id" : "109414082410185", "name" : "National University of Ireland, Galway", "_id" : ObjectId("517fc1e66d19040200004fb5") } ], "jobs" : [ { "id" : "1602115006654
export default {
input: {
display: 'inline-block',
width: '100%',
height: '100%',
lineHeight: 0
},
browser: {
position: 'absolute',
width: '100%',
@kof
kof / decorated-component.js
Last active October 10, 2015 13:25
React component without extends.
import {component} from 'react'
@component
export default class MyComponent {
componentDidMount() {
}
render() {
}
}
@kof
kof / bootstrap.js
Created March 30, 2011 22:52
bootstrap file for mongoose models
var fs = require('fs'),
m = require('mongoose');
fs.readdirSync(__dirname).forEach(function(filename) {
var schamaName = filename.replace(/\.js$/, ''),
Schema = require('./' + schemaName);
m.model(schemaName, Schema);
});