Skip to content

Instantly share code, notes, and snippets.

@okuyan
okuyan / workflow.yml
Last active July 21, 2020 02:41
Deploy Gatsby site on Firebase hosting using Github actions
name: Build and Deploy
on:
push:
branches:
- master
jobs:
build:
name: Build
runs-on: ubuntu-latest
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
var add = function(x, y) {
var addFive = function(num){
if (this.hoge === undefined) {
this.hoge = 1;
}
return num + 5 + this.hoge;
};
console.log(addFive(4)); //10
console.log(addFive.apply(null, [4])); //10
@okuyan
okuyan / gist:382624f6589bd7f35d3f
Created December 15, 2014 18:28
[js] 50% chance
var a = b = 0;
for (i = 0; i < 100; i++) {
if (Math.round( Math.random()) > 0) {
a++;
} else {
b++;
}
}
CREATE [UNIQUE|FULLTEXT|SPATIAL] INDEX index_name
[index_type]
ON tbl_name (index_col_name,...)
[index_option]
[algorithm_option | lock_option] ...
//CREATE INDEX idx_foo_column ON tbl_bar (foo_column DESC)
@okuyan
okuyan / gist:8eb768e07c6e94c41974
Last active August 29, 2015 14:07
for loop micro-optimizations
//before
for (var i = 0, max = myarray.length; i < max; i + +) {
// do something with myarray[ i]
}
//after
var i, myarray = [];
for (i = myarray.length; i--) {
// do somthing with myarray[i]
@okuyan
okuyan / jsbin.qoguw.js
Last active August 29, 2015 14:07
Get query string
var parseQueryString = function(queryString) {
var params = {},
queries, temp, i, l;
queries = queryString.split('&');
l = queries.length;
for (i = 0; i < l; i++) {
temp = queries[i].split('=');
@okuyan
okuyan / jsbin.modano.js
Created September 29, 2014 21:07
javascript php foreach
//javascript php foreach equivalent
var obj = {prop1: 5, prop2: 13, prop3: 8};
for (var item in obj) {
console.log(item + ':' + obj[item]);
}
@okuyan
okuyan / jsbin.baraha.js
Last active August 29, 2015 14:07
Javascipt - array leteral
var arr = new Array(2, 3, 4);
console.log(arr); // [2, 3, 4]
var arr2 = new Array(2);
console.log(arr2); // [undefined, undefined] ew...
console.log(arr2.length); //2
// using array literal
var a = [3.14];
console.log( a[ 0]); // 3.14
//antipattern
var arr = new Array("apple", "google", "yahoo");
//the exact same array
var arr = ["apple", "google", "yahoo"];
console.log(typeof arr); // "object"
console.log(arr.constructor === Array); // true