Skip to content

Instantly share code, notes, and snippets.

View myeonwoo's full-sized avatar

Myeonwoo Lim myeonwoo

View GitHub Profile
@myeonwoo
myeonwoo / starting_model.php
Last active March 5, 2020 06:48
PHP: Starting-Template-Model
<?php
/**
* 관련 테이블
* Start
*/
class M_survey extends CI_Model{
function __construct(){
parent::__construct();
$this->db = $this->load->database("global", TRUE);
}
@myeonwoo
myeonwoo / start_controller.php
Created November 6, 2017 06:48
PHP: Starting-Template-Controller
<?php
class Start extends CI_Controller {
function __construct() {
parent::__construct();
$this->data = array();
}
public function index()
{
$this->main();
@myeonwoo
myeonwoo / starting_template.html
Last active March 14, 2018 01:31
HTML: Starting Template
<div id="wrap">
<div class="row">
<div class="col-lg-12">
<h3></h3>
</div>
</div>
<hr/>
<div>
<div class="col-lg-12">
<div class="panel panel-default">
@myeonwoo
myeonwoo / remove_item_in_array.js
Last active March 4, 2020 09:57
JavaScript: function - remove item in array
function remove_item(array, element) {
const index = array.indexOf(element);
if (index !== -1) {
array.splice(index, 1);
}
}
// deep copy json
JSON.parse(JSON.stringify(object));
@myeonwoo
myeonwoo / tree.js
Created October 9, 2017 16:58
JavaScript: Data Structure - Tree
function Node(data) {
this.data = data;
this.parent = null;
this.children = [];
}
function Tree(data) {
var node = new Node(data);
this._root = node;
}
@myeonwoo
myeonwoo / linked_list.js
Created October 9, 2017 07:13
JavaScript: Data Structure - Linked List
function Node(value) {
this.data = value;
this.previous = null;
this.next = null;
}
function SinglyList() {
this._length = 0;
this.head = null;
}
@myeonwoo
myeonwoo / stack.js
Last active September 6, 2018 02:57
JavaScript: Data Structure - Stack
function Stack() {
this._size = 0;
this._storage = {};
}
Stack.prototype.push = function(data) {
var size = ++this._size;
this._storage[size] = data;
};
@myeonwoo
myeonwoo / queue.js
Created October 9, 2017 06:44
JavaScript: Data Structure - Queue
function Queue() {
this._oldestIndex = 1;
this._newestIndex = 1;
this._storage = {};
}
Queue.prototype.size = function() {
return this._newestIndex - this._oldestIndex;
};
@myeonwoo
myeonwoo / hierarchy.php
Created October 9, 2017 06:18
PHP: Data Structure - Hierarchy
<?
class Hierarchy {
private static $hierarchy;
private static $lookup;
// Nodes can be any objects that have IDs (id) and a parent IDs (parent)
public static function buildTree($nodes){
// Initialize hierarchy and lookup arrays
self::$hierarchy = array();
self::$lookup = array();
// Walk through nodes
@myeonwoo
myeonwoo / tableToSql.js
Created September 21, 2017 08:16 — forked from rnaffer/tableToSql.js
Export table to excel with pure javascript
var tableToExcel = (function() {
var uri = 'data:application/vnd.ms-excel;base64,'
, template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><?xml version="1.0" encoding="UTF-8" standalone="yes"?><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>'
, base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) }
, format = function(s, c) { return s.replace(/{(\w+)}/g, function(m, p) { return c[p]; }) };
return function(table, name) {
if (!table.nodeType) table = document.getElementById(table);
var ctx = { worksheet: name || 'Worksheet', table: table.innerHTML };
window.location.href = uri + base64(format(template, ctx));
};