Skip to content

Instantly share code, notes, and snippets.

@prewk
prewk / observe-property.ts
Created March 22, 2022 12:07 — forked from dscheerens/observe-property.ts
Property observe function
import { BehaviorSubject, Observable } from 'rxjs';
/**
* Observes the specified property and returns a stream that emits all values which are assigned to the property. When subscribing to the
* resulting stream it will always first emit the current value of the property, followed by all new values that are assigned to it.
*
* @param target Object containing the property.
* @param key Key of the property that is to be observed.
* @returns A stream of all values that are assigned to the specified property, starting with the current value of the property.
*/
@prewk
prewk / component.jsx
Last active January 13, 2016 13:09 — forked from anonymous/component
import Component from 'react-pure-render/component';
import React, {PropTypes} from 'react';
import {Link} from 'react-router';
export default class Header extends Component {
static propTypes = {
msg: PropTypes.object.isRequired,
pathname: PropTypes.string.isRequired,
viewer: PropTypes.object
@prewk
prewk / taggable.js
Created January 12, 2016 07:32
Bookshelf.js polymorphic problem
var bookshelf = require('./bookshelf');
var Post = require('./post');
/*
Schema:
posts:
id: PRIMARY
title: VARCHAR
,,,,,,,,,,,,,,,.,.....................................................................................................................``````````````````````````````````````````````````````````````````
,,,,,,,,,,,,,,,,,,,.,.,,,.,,...........................................................................................................`````````````````````````````````````````````````````````````````
,,,,,,..,,,,,,,,,,,,,,.,,,.............................................................................................................`````````````````````````````````````````````````````````````````
,,,,,,...,,,,,,,,,,,,,,................................................................................................................`````````````````````````````````````````````````````````````````
.,,,,....,,,,,,.,,,,,,,...............................................................................................................``````````````````````````````````````````````````````````````````
..,......,,,,......
#include <SFML/Graphics.hpp>
// Map of sprite vectors, mapped by name
std::map<std::string, std::vector<sf::Sprite>> sprites;
sf::Texture texture;
// Create some sprite frames and map to a name
void defineSprite(const std::string& name, const std::vector<sf::IntRect>& frames) {
std::vector<sf::Sprite> namedFrames(frames.size());
// -----------------
// scripts/breeds.json (This is okay, I've used it in another context and its interpreted correctly)
// -----------------
{
"Warrior": {
"sheet": "resources/Fighter-F-01.png",
"stats": {
"health": 100,
"strength": 50,
"intelligence": 10
class SpriteSheet
{
public:
SpriteSheet();
SpriteSheet(const std::string& filename);
void defineSprite(std::string name, std::vector<sf::IntRect> frames);
const sf::Sprite& getFrame(const std::string& name, int frame);
sf::Texture texture;
var menuItems = Immutable.List.of(
{ parent_id: 0, id: 1 },
{ parent_id: 1, id: 2 },
{ parent_id: 1, id: 2 }
);
var results1 = menuItems
.filter(function(menuItem) { return menuItem.parent_id === 1; }) // Filter out items with parent_id = 1
.sort(function(childA, childB) { return childA.sort_order - childB.sort_order; }); // Sort them by sort_order