Skip to content

Instantly share code, notes, and snippets.

View akirattii's full-sized avatar

Akira TANAKA akirattii

View GitHub Profile
@akirattii
akirattii / drawer-slide-menu-example.html
Created March 2, 2014 06:44
Example of drawer slide menu using jQuery
<!DOCTYPE html>
<html>
<head>
<title>Layout Example</title>
<style type="text/css">
* {
margin: 0;
padding: 0;
}
html, body {
@akirattii
akirattii / sublime-text-like.css
Created January 18, 2014 08:57
Sublime Text Like Theme for Brackets. It's inspired by 'Monokai Dark Soda' Theme in 'Themes' plugin. Installation: copy to ~/.config/Brackets/extensions/user/themes/theme/ and restart Brackets.
.cm-s-sublime-text-like.CodeMirror {
background-color: #242424;
color: #fff;
}
.CodeMirror div.CodeMirror-cursor {
border-left: 1px solid #f8f8f0;
z-index: 3;
}
const Sanitizer = {
encode: function(str) {
if (!str) return;
str = "" + str;
return str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#39;');
},
decode: function(str) {
if (!str) return;
str = "" + str;
return str.replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&quot;/g, '"').replace(/&#39;/g, '\'').replace(/&amp;/g, '&');
@akirattii
akirattii / gist:460b6c507d9c5b6f51caea985a12da27
Created June 21, 2016 11:39
CamelCase <-> HyphenCase converter
// camelCase -> hyphenCase
function camelToHyphenCase: function(str) {
return str.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
}
// hyphenCase -> camelCase
function hyphenToCamelCase(str) {
return str.replace(/-([a-z])/g, function(g) {
return g[1].toUpperCase();
});
}
@akirattii
akirattii / gist:efb54a532d6c8ee0c5cbc5747ca6cbf0
Last active June 24, 2016 22:59
Getting some related words from wikipedia(ja) on Meteor
// server/hoge.js
const re = /\[\[(.+?)\]\]/g; // matches '*[[hoge]]' or '* [[hoge]]'
const reRedirect = /^\#REDIRECT\s?\[\[(.+)\]\]/; // matches '#REDIRECT [[hoge]]'
const reRelatedHeader = /\=\=\s?関連項目\s?\=\=/;
function getEndpoint(title) {
title = encodeURIComponent(title);
return `https://ja.wikipedia.org/w/api.php?action=query&titles=${title}&prop=revisions&rvprop=content&format=json`;
}
@akirattii
akirattii / array_op.js
Created June 24, 2016 23:01
配列操作のsnippets
// 配列の重複を削除
var arr = ["", "", "hoge", "baa", "hogege", "", "foo", "", ""];
var newArr = arr.filter((x, i, self) => self.indexOf(x) === i);
// newArr -> ["", "hoge", "baa", "hogege", "foo"]
@akirattii
akirattii / loadImage.js
Created June 29, 2016 22:59
Downloads and views an image on Chrome App and Extension
/**
* dl an external image resource and append it as an img element into the rootEl
*
* @param {String}
* image resource's url
* @param {Element} Optional
* root element to be appended an img element.
* @param {Function} Optional
* callback function. 'function(imgEl){...}'
@akirattii
akirattii / AmazonRecommendItemsGetter.js
Created June 29, 2016 23:01
Snippet for amazon recommend items
// manifest.json
/*
...
"permissions": [
"*://*.amazon.co.jp/*",
"*://*.amazon.com/*"
or
"<all_urls>"
],
...
@akirattii
akirattii / ArrayBufferToStringOrDom.js
Created July 14, 2016 12:00
From ArrayBuffer to String | From ArrayBuffer of html to DOM
// buf is ArrayBuffer
function ab2str(buf) {
return td.decode(new Uint8Array(buf));
}
function ab2dom(buf) {
let html = ab2str(buf);
let rootEl = document.createElement('html');
rootEl.innerHTML = html;
@akirattii
akirattii / example-WSC.ChromeSocketXMLHttpRequest.js
Created July 14, 2016 12:05
Over the unsafe header restriction of Chrome apps using WSC.ChromeSocketXMLHttpRequest
// First,
// $ git clone https://github.com/kzahel/web-server-chrome.git
// $ ./minimize.sh
// and ...
// load wsc-chrome.min.js in your html
function request(url, headers, cb) {
let xhr = new WSC.ChromeSocketXMLHttpRequest;
let headersLen = headers.length;
let k, v;