Skip to content

Instantly share code, notes, and snippets.

View samsch's full-sized avatar

Lumina Scheiderich samsch

View GitHub Profile
@samsch
samsch / connect.js
Last active December 30, 2015 16:52 — forked from dagda1/connect.js
import React, {Component} from 'react';
import {connect} from 'react-redux';
import FunctionPlot from './function-plot';
require("../../css/functions.css");
function mapStateToProps(state) {
return {
expression: state.expression
<?php
namespace AppBundle\Services;
use AppBundle\Entity\AnEntityRepo;
use AppBundle\Services\OtherService;
use AppBundle\Services\ThirdService;
class Features
{
@samsch
samsch / README.md
Created January 21, 2016 16:38
How to set PDO MySQL SSL Constants in Symfony

I created this because I was frusterated by having to change the integer values when the environments changed for my projects. A simple update of PHP 5.6 (I think it was PHP 5.6.16 to 5.6.17) changed the integer values, which are usually what is suggested to be used in parameters.yml or config.yml.

By using the constants, you don't have to worry about stupid stuff like that. (Since that's what they were designed for.)

@samsch
samsch / app.js
Last active January 25, 2016 17:26
Example of rendering to two React instances (e.g., different parts of a page) as a single component.
var Hello = React.createClass({
render: function() {
return <div>{this.props.name}</div>;
}
});
var HelloInput = React.createClass({
render: function() {
return (
<div><input value={this.props.name} onChange={ev=>this.props.update(ev.target.value)}/></div>
@samsch
samsch / actions.js
Created February 9, 2016 19:48
Possible solution to Redux action type name confilcts.
//Action type constants don't have to have the same name as their value.
//Really, the const string value doesn't even have to be related to the action itself.
const UPDATE = 'randomValueGeneratedSomehow';
let updateThing = function(newValue) {
return {
type: UPDATE,
payload: newValue,
}
}
@samsch
samsch / EmFactory.php
Last active November 14, 2018 10:59
Symfony dynamic DB connection
<?php
namespace AppBundle\Services\Factories;
//Inject the EM and Connection for the configured em that needs to be dynamic.
//I think you can actually just inject the EM, and call ->getConnection() it.
use Doctrine\ORM\EntityManager;
use Doctrine\DBAL\Connection;
//This service gets the dynamic DB creds from the request/user/whatever.
@samsch
samsch / Resources.md
Last active April 4, 2016 13:41
Reactjs, Redux, Webpack/Browserify, Babel Resources.

Before trying to learn React or Redux, or use Webpack/Browserify or Babel, you should make sure you know Javascript at least reasonably well. A great resource learning Javascript is EloquentJS. If you have never programmed before, another great place to learn JS is Codecademy. The best resource for referencing the basic web languages (HTML, CSS, Javascript, and the DOM API) is the Mozilla Developer Network, commonly referred to as MDN.

Basic setup

React

@samsch
samsch / BasicReactRenderingByListener.js
Last active February 29, 2016 16:36
Basic React rendering by listener.
//Some store thing that has onUpdate as a method for setting listeners.
store.onUpdate(function(newState) {
ReactDOM.render(
<App state={newState} />,
document.getElementById("root")
);
});
//You either need to call render once here to get things started, or cause a state update.
ReactDOM.render(
@samsch
samsch / README.md
Last active March 17, 2016 13:43
Basic selectors idea.

The state shape would be something like:

{
    products: [
        {
            price: 7500,
            name: "Some product",
            //other details
        },
 {
@samsch
samsch / component.jsx
Last active March 18, 2016 18:01
React performance problem: Creating a new function on every render, when you need parameters.
var React = require('react');
//This would be passed props like:
{
btns: [
{id: 'btn1', label: 'Button 1'},
{id: 'btn2', label: 'Button 2'},
{id: 'btn3', label: 'Button 3'},
],
onBtnClick: function(btnId) {