Skip to content

Instantly share code, notes, and snippets.

View SiestaMadokaist's full-sized avatar

Rama Patria Himawan SiestaMadokaist

View GitHub Profile
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
import os
import re
class HorribleSubs:
regex = re.compile("\[HorribleSubs\] (.+) - (\d+) \[\d+p\].*(\.\w+$)")
def __init__(self, path):
parsed = HorribleSubs.regex.findall(path)
title, episode, extension = parsed[0]
@SiestaMadokaist
SiestaMadokaist / globals__.py
Created September 1, 2015 15:36
dammit python!
def main(somestring):
g = globals()
for i, char in enumerate(somestring):
if(ord(char) in range(ord("0"), ord("9"))):
variable_name = "my_int_{}".format(i)
g[variable_name] = int(char)
else:
variable_name = "my_char_{}".format(i)
g[variable_name] = char
print(my_char_0)