Skip to content

Instantly share code, notes, and snippets.

View octopitus's full-sized avatar

Luy Tran octopitus

View GitHub Profile
@octopitus
octopitus / BaseModel.php
Last active August 29, 2015 14:01 — forked from JonoB/gist:6637861
<?php namespace Tmb;
use Illuminate\Database\Eloquent\Model as Eloquent;
use Illuminate\Validation\Validator;
class BaseModel extends Eloquent
{
/**
* Error message bag
<?php
class BlogController extends Controller
{
/**
* Posts
*
* @return void
*/
public function showPosts()
@octopitus
octopitus / Model.php
Last active August 29, 2015 14:10
override save() method in Model.php to composite keys
<?php
class BaseModel extends Eloquent {
public $incrementing = false;
protected $primaryKey = ['id', 'another_key'];
public function save(array $options = [])
{
@octopitus
octopitus / README.md
Last active February 27, 2016 09:30
DOM event listener made easy (Writen in ES2015)

Example

Let's say that we have a #container like this

<div id="container">
  <div class="foo">Foo</div>
  <div class="bar">Bar</div>
  <div class="baz">Baz</div>
</div>
@octopitus
octopitus / h.js
Last active February 29, 2016 04:32
2kb syntax highlighter
function h(s, f, t, e, c, r, m, l, p) {
t = '';
p = [];
e = function(t) {
return (t.replace(/[<&]/g, function(c) {
return '&#' + c.charCodeAt() + ';'
}))
};
c = function(_) {
return (_ = s.replace(/^(\s*)(\/(\/.*|\*([^]*?\*\/|[^]*)))/, function(_, w, m) {
@octopitus
octopitus / functional-utils.js
Created April 20, 2016 13:56 — forked from bendc/functional-utils.js
A set of pure and immutable ES2015 functions aimed to make functional JavaScript more idiomatic.
// array utils
// =================================================================================================
const combine = (...arrays) => [].concat(...arrays);
const compact = arr => arr.filter(Boolean);
const contains = (() => Array.prototype.includes
? (arr, value) => arr.includes(value)
: (arr, value) => arr.some(el => el === value)
@octopitus
octopitus / string_compression.js
Last active June 6, 2016 12:35
String compression
function compressString(str) {
const arrayOfChars = str.split('')
let currentChar = arrayOfChars[0]
let timeOfAppear = 1
const mapOfChars = arrayOfChars.slice(1).reduce((result, value, index) => {
if (value === currentChar) {
timeOfAppear++
return result
@octopitus
octopitus / english_phrase_to_integer.js
Created June 6, 2016 16:22
convert English phrase to integer
const splitChars = /\b(billion|million|thoudsand|hundred)s?/g
const points = {
billion: 1000000000,
million: 1000000,
thoudsand: 1000,
hundred: 100
}
const digits = {
@octopitus
octopitus / README.md
Last active August 14, 2016 02:47
Go fun yourself. With terminal.

Install fortune & cowsay

brew install fortune cowsay coreutils

Install lolcat

Make sure you have rvm [Install] and then put this line to the bottom of your shell (.bashrc or .zshrc):

[[ -s "$HOME/.rvm/scripts/rvm" ]] &amp;&amp; source "$HOME/.rvm/scripts/rvm" # This load rvm
// Asume that your card has ID
const card = {
id: 'foo',
category: 'bar'
// ...
}
// This is how your app state looks like
const appState = {
entities: {