Skip to content

Instantly share code, notes, and snippets.

# x - 2.y + z = 9
# 2.x - y = 4
# y + z = 12
[x] [1, -2, 1] [9]
[y] * [2, -1, 0] = [4]
[z] [0, 1, 1] [12]
# if we want to find out the x, y, and z, we can just
class LinearEquation
attr_reader(:eq)
extend Memoist
def initialize(&eq)
raise ArgumentError, "equation must be passed" unless block_given?
@eq = eq
end
def raw_equations
require File.expand_path('../linear_equation', __FILE__)
le = LinearEquation.new do
x - 2.y + z = 9
2.x - y = 4
y + z = 12
end
puts(le.solution)
# user.rb
def method_missing?(methodname)
if(user_info.respond_to?(methodname))
user_info.send(methodname)
else
raise NoMethodError, methodname
end
end
table.columns.each do |column|
define_method("find_by_#{column.name}") do |value|
... # somecode
connection.call("SELECT #{selected_fields} WHERE #{column.name} = #{value}")
end
end
@SiestaMadokaist
SiestaMadokaist / reducer.jsx
Last active December 2, 2016 00:58
todo-reducer
import Immutable from 'immutable'
import { Actions } from 'actions'
const defaultState = new Immutable.List();
function reducer(state = defaultState, action){
if(action.type === Actions.STATE_REPLACE){
...
return replacedState;
}else if(action.type === Actions.REMOVE_STATE){
...
return removedState;
@SiestaMadokaist
SiestaMadokaist / enemies-view.jsx
Last active December 2, 2016 00:32
just something.
import React from 'react';
import EnemyView from 'components/Seven/EnemyView';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import EnemiesActions from 'actions/Seven/EnemiesActions';
@connect(state => ({}))
export default class EnemiesView extends React.Component {
render(){
@SiestaMadokaist
SiestaMadokaist / htmlparser.rb
Created September 28, 2016 15:24
simple_html_parser
require 'memoist'
class HTMLParser
extend Memoist
ReversedParser = /(?<after>[^>]*)>(?<tag>[^\/]+)\/<(?<body>.*?)>(?<tag_attr>[^>]*)\k<tag><(?<before>.*)/
attr_reader(:raw_string)
def initialize(raw_string)
@raw_string = raw_string.gsub("\n", "")
end
@SiestaMadokaist
SiestaMadokaist / install_ffmpeg_ubuntu.sh
Created June 28, 2016 12:49 — forked from xdamman/install_ffmpeg_ubuntu.sh
Install latest ffmpeg on ubuntu 12.04 or 14.04
#!/bin/bash
# Bash script to install latest version of ffmpeg and its dependencies on Ubuntu 12.04 or 14.04
# Inspired from https://gist.github.com/faleev/3435377
# Remove any existing packages:
sudo apt-get -y remove ffmpeg x264 libav-tools libvpx-dev libx264-dev
# Get the dependencies (Ubuntu Server or headless users):
sudo apt-get update
@SiestaMadokaist
SiestaMadokaist / json_query.rb
Created April 26, 2016 05:19
libs to querying a deeply nested json.
require "hashie"
require "memoist"
class HashQuery
attr_reader(:path)
# @param root [NestedHash]
# @param query [String]
def initialize(root, path)
@root = root
@path = path