Skip to content

Instantly share code, notes, and snippets.

View octopitus's full-sized avatar

Luy Tran octopitus

View GitHub Profile
@octopitus
octopitus / js-toSlug.js
Created September 20, 2016 08:39 — forked from juanmhidalgo/js-toSlug.js
JavaScript toSlug()
String.prototype.toSlug = function(){
st = this.toLowerCase();
st = st.replace(/[\u00C0-\u00C5]/ig,'a')
st = st.replace(/[\u00C8-\u00CB]/ig,'e')
st = st.replace(/[\u00CC-\u00CF]/ig,'i')
st = st.replace(/[\u00D2-\u00D6]/ig,'o')
st = st.replace(/[\u00D9-\u00DC]/ig,'u')
st = st.replace(/[\u00D1]/ig,'n')
st = st.replace(/[^a-z0-9 ]+/gi,'')
st = st.trim().replace(/ /g,'-');
@octopitus
octopitus / PanResponderExample.jsx
Created December 21, 2016 15:05
An example of RN's PanResponder
/* eslint-disable */
import React from 'react'
import {View, Animated, PanResponder} from 'react-native'
const styles = {
container: {
backgroundColor: '#FFFFFF',
justifyContent: 'center',
alignItems: 'center',
flex: 1
@octopitus
octopitus / dz602xshift.json
Created January 14, 2019 14:42
My DZ60 pre-configuration
{"version":1,"keyboard":{"keys":[{"id":0,"legend":"~\n`","state":{"x":0,"y":0,"r":0,"rx":0,"ry":0,"w":1,"h":1,"x2":0,"y2":0,"w2":0,"h2":0},"row":0,"col":0,"keycodes":[{"id":"KC_GESC","fields":[]},{"id":"KC_APP","fields":[]},{"id":"KC_TRNS","fields":[]},{"id":"KC_TRNS","fields":[]},{"id":"KC_TRNS","fields":[]},{"id":"KC_TRNS","fields":[]},{"id":"KC_TRNS","fields":[]},{"id":"KC_TRNS","fields":[]},{"id":"KC_TRNS","fields":[]},{"id":"KC_TRNS","fields":[]},{"id":"KC_TRNS","fields":[]},{"id":"KC_TRNS","fields":[]},{"id":"KC_TRNS","fields":[]},{"id":"KC_TRNS","fields":[]},{"id":"KC_TRNS","fields":[]},{"id":"KC_TRNS","fields":[]}]},{"id":1,"legend":"!\n1","state":{"x":1,"y":0,"r":0,"rx":0,"ry":0,"w":1,"h":1,"x2":0,"y2":0,"w2":0,"h2":0},"row":0,"col":1,"keycodes":[{"id":"KC_1","fields":[]},{"id":"KC_F1","fields":[]},{"id":"KC_TRNS","fields":[]},{"id":"KC_TRNS","fields":[]},{"id":"KC_TRNS","fields":[]},{"id":"KC_TRNS","fields":[]},{"id":"KC_TRNS","fields":[]},{"id":"KC_TRNS","fields":[]},{"id":"KC_TRNS","fields":[]},{"
/*
Take and modify from https://gist.github.com/trusktr/1e5e516df4e8032cbc3d
~/Library/KeyBindings/DefaultKeyBinding.Dict
This file remaps the key bindings of a single user on Mac OS X 10.5 to more
closely match default behavior on Windows systems. This makes the Command key
behave like Windows Control key. To use Control instead of Command, either swap
Control and Command in Apple->System Preferences->Keyboard->Modifier Keys...
@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 / 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');
}