Skip to content

Instantly share code, notes, and snippets.

View c0d0g3n's full-sized avatar

Bruno c0d0g3n

View GitHub Profile
@c0d0g3n
c0d0g3n / snippets.cson
Created August 23, 2017 14:07
my atom snippets
# Your snippets
#
# Atom snippets allow you to enter a simple prefix in the editor and hit tab to
# expand the prefix into a larger code block with templated values.
#
# You can create a new snippet in this file by typing "snip" and then hitting
# tab.
#
# An example CoffeeScript snippet to expand log to console.log:
#
@c0d0g3n
c0d0g3n / EditableContainer.jsx
Last active February 11, 2021 11:13
React: double click to edit, blur to save and exit.
import React from 'react'
import settings from '../settings.js'
import Field from '../styles/FieldStyle.jsx'
export default class EditableContainer extends React.Component {
constructor (props) {
super(props)
// init counter
this.count = 0
@c0d0g3n
c0d0g3n / MuteClicksComponent.jsx
Created July 29, 2017 13:21
Little HOC that stops event propagation (also prevents default behavior of link/button/... if `strict="true"` is passed)
import React from 'react'
export default class MuteClicksComponent extends React.Component {
handleClick (childClickHandler) {
return (e) => {
e.stopPropagation()
// also prevent child link/button/... from working if neccesary
if (this.props.strict) e.preventDefault()
@c0d0g3n
c0d0g3n / clickStream.js
Created July 20, 2017 19:00
Turn React events into rxjs streams (example: single click, double click...)
// stream of clicks
// onClick should call this.handleClick.bind(this) for it to work
const click$ = Observable
.create((observer) => {
// method puts clicks into stream
this.handleClick = (event) => {
observer.next(event)
}
})
.share() // allow multiple branches
// components/ComponentExample.js
import React from 'react'
import {connect} from 'react-redux'
import endpointExample from '../endpoints/endpointExample.js'
@connect((state, props) => {
return {
example: endpointExample(state, props)
}
@c0d0g3n
c0d0g3n / findFiles.js
Last active February 15, 2019 09:45
Recursively find files in a directory using Bluebird promises
const Promise = require('bluebird')
const fs = require('fs')
Promise.promisifyAll(fs)
const path = require('path')
// Usage:
// const findFiles = require('path/to/findFiles.js')
// findFiles('dir/to/search/in')
// Arg 'files' is used to propagate data of recursive calls to the initial call
// If you really want to, you can use arg 'files' to manually add some files to the result
@c0d0g3n
c0d0g3n / help.js
Created May 3, 2017 16:28
Explaining how Mongoose setters work
// dependencies
let mongoose = require('mongoose')
let Promise = require('bluebird')
mongoose.Promise = Promise
// connect to local db help
mongoose.connect("mongodb://localhost/help")
let db = mongoose.connection
db.on('error', (err) => {
return console.error('Connection error:', err)
@c0d0g3n
c0d0g3n / bug.js
Created May 2, 2017 18:20
Bug: Mongoose pre validate sub doc middleware Unhandled Rejection
let mongoose = require('mongoose')
let Promise = require('bluebird')
mongoose.Promise = Promise
mongoose.connect("mongodb://localhost/bug")
let db = mongoose.connection
db.on('error', (err) => {
return console.error('Connection error:', err)
})
@c0d0g3n
c0d0g3n / bug.js
Last active April 30, 2017 15:36
Mongoose bug: SchemaType Boolean tries to convert input
mongoose = require("mongoose")
mongoose.connect("mongodb://localhost/bug")
let db = mongoose.connection
db.on('error', (err) => {
return console.error('Connection error:', err)
})
testSchema = mongoose.Schema({
test: {
@c0d0g3n
c0d0g3n / apache.md
Last active January 5, 2017 18:26
Apache manual install on Windows: Checklist

Based on: https://www.sitepoint.com/how-to-install-apache-on-windows/ (outdated)

Install Apache

Donwload binary and requirements

Unzip the binary anywhere you want apache installed

Note apache is configured to run under c:\name_of_folder_in_zip, if you install apache anywhere else, you should search the config file for c:\name_of_folder_in_zip and replace with your install directory.

Install as a windows process