Skip to content

Instantly share code, notes, and snippets.

View octopitus's full-sized avatar

Luy Tran octopitus

View GitHub Profile
@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 / expression.go
Last active February 15, 2022 10:39
Simple Infix to Postfix conversion in Golang using stack.
package main
import (
"strings"
)
func IsOperator(c uint8) bool {
return strings.ContainsAny(string(c), "+ & - & * & /")
}
@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 = [])
{
<?php
class BlogController extends Controller
{
/**
* Posts
*
* @return void
*/
public function showPosts()
@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
@octopitus
octopitus / slugify.php
Created May 12, 2014 07:14
SEO friendly url converter for Vietnamese
<?php
/**
* Take from https://gist.github.com/alixaxel/5562152 with some edits
*/
function slugify($string, $slug = '-', $extra = null) {
if (strpos($string = htmlentities($string, ENT_QUOTES, 'UTF-8'), '&') !== false) {
$string = html_entity_decode(preg_replace('~&([a-z]{1,2})(?:acute|caron|cedil|circ|grave|lig|orn|ring|slash|tilde|uml);~i', '$1', $string), ENT_QUOTES, 'UTF-8');
}