Skip to content

Instantly share code, notes, and snippets.

@birowo
birowo / .htaccess
Last active November 14, 2016 01:50
PHP routing . contoh penerapan untuk upload gambar. taruh file .htaccess & rute.php (& file lainnya di kasus ini) di document root (folder htdocs kalau di xampp) . akses browser : http://localhost
RewriteEngine On
RewriteRule ^.*\.php$ rute.php [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.*$ rute.php [QSA,L]
@birowo
birowo / chatlongpoll.php
Last active November 14, 2016 23:06
php ajax longpoll . contoh untuk broadcast message . silahkan ubah var. $rahasia , kode rahasia ini dipakai untuk mencegah merubah nilai $id terakhir di sisi client. silahkan ubah juga host, username & password mysql jika diperlukan.di browser akses : http://localhost/phplongpoll.php
<?php
set_time_limit(0);
$rahasia = '$r4h@5!4';
$dbname = 'dbname=dbchat';
include 'kueridb.php';
$err = 0;
$rslt = kueridb($err, 'SELECT MAX(id) as id FROM chat');
if($err) die("salah kueri: $err");
if(empty($rslt[0]['id'])){
$id = 0;
@birowo
birowo / nodesse.html
Last active November 17, 2016 07:31
server sent event dengan NODE.JS . contoh untuk broadcast message. jalankan >node nodesse di terminal dari path dimana file-file berikut disimpan. coba akses browser: http://localhost di 2/lebih instance browser/client . SSE adalah https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events
<html>
<head>
<title></title>
</head>
<body>
<textarea id="daftar" readonly></textarea><br>
<input id="pesan"><br>
<button onclick="kirim()">kirim</button>
<script>
@birowo
birowo / belajar_nodejs.md
Last active November 22, 2016 06:02
tutorial belajar node.js untuk pemula

tutorial belajar node.js untuk pemula

membuat & memahami webserver

buat file skrip namai webserver.js (simpan misal di folder latihan yang sudah kita buat) sbb. :

'use strict';

//method parse dari modul url dipakai untuk memecah url menjadi bagian pathname dan bagian query

const urlParse = require('url').parse;

@birowo
birowo / binaryAjax.php
Last active November 24, 2016 06:17
upload file secara binary ajax dengan fallback secara multipart form . contoh untuk upload gambar. akses http://localhost/binaryUpload.html
<?php
$mime = ['jpg'=>'image/jpeg; charset=binary', 'png'=>'image/png; charset=binary'];
$buffer = file_get_contents('php://input');
$validExt = array_keys($mime);
$fileExt = array_search(finfo_buffer(finfo_open(FILEINFO_MIME), $buffer, FILEINFO_MIME), $mime);
if(false === in_array($fileExt, $validExt)){
die("INVALID TYPE, type file yang valid: ".implode(' / ', $validExt));
}
$uploadFileID = uniqid('binaryAjax', true).'.'.$fileExt;
file_put_contents($uploadFileID, $buffer);
@birowo
birowo / hashTable.js
Created November 29, 2016 00:26 — forked from alexhawkins/hashTable.js
A Simple Hash Table in JavaScript
/*HASH TABLE - a dictionary/hash map data structure for storing key/value pairs. Finding
an entry in a hash table takes O(1) constant time(same for 10 as 1 billion items). Whereas
finding an item via binary search takes time proportional to the logarithm of
the item in the list O(logn). Finding an item in a regular old list takes time proportional to
the length of the list O(n). Very slow. Hash Tables = very fast */
var makeHashTable = function(max) {
var storage = [],
hashTableMethods = {
@birowo
birowo / README.md
Created November 29, 2016 03:15 — forked from sebastianwebber/README.md
Compilation of the Uber Facts on PostgreSQL to MySQL Migration

Uber facts

Original posts/information

Key points

  • ~50GB MySQL Application
  • Main motivation: PostGis
  • Migration made with a custom tool(xml2pgcopy) and mysqldump on 45min
@birowo
birowo / coba_ekpres.js
Last active December 15, 2016 04:00
konsep middleware di express.js . pakai npm install express.js . buat file skrip misal: coba_express.js seperti berikut: . jalankan dari terminal: >node coba_express . dari browser akses: http://localhost:3000 . lihat diterminal console.log: acedb . jika ingin buat seperti express.js harus faham konsep/cara-kerja express.js , versi sederhananya …
'use strict';
/*jika kita buat sendiri yang seperti express.js , versi sederhananya seperti ini: */
function ekpres(){
const http = require('http');
let middlewares = null, len = 0;
function onRekuesCB(rekues, respon){
let idx = -1;
!function lanjut(){
if(++idx < len)return middlewares[idx](rekues, respon, lanjut);
}();
@birowo
birowo / readme.md
Created December 11, 2016 04:55 — forked from coolaj86/how-to-publish-to-npm.md
How to publish packages to NPM

Getting Started with NPM (as a developer)

If you haven't already set your NPM author info, now you should:

npm set init.author.name "Your Name"
npm set init.author.email "you@example.com"
npm set init.author.url "http://yourblog.com"

npm adduser

@birowo
birowo / array_iteration_thoughts.md
Created January 13, 2017 08:01 — forked from ljharb/array_iteration_thoughts.md
Array iteration methods summarized

While attempting to explain JavaScript's reduce method on arrays, conceptually, I came up with the following - hopefully it's helpful; happy to tweak it if anyone has suggestions.

Intro

JavaScript Arrays have lots of built in methods on their prototype. Some of them mutate - ie, they change the underlying array in-place. Luckily, most of them do not - they instead return an entirely distinct array. Since arrays are conceptually a contiguous list of items, it helps code clarity and maintainability a lot to be able to operate on them in a "functional" way. (I'll also insist on referring to an array as a "list" - although in some languages, List is a native data type, in JS and this post, I'm referring to the concept. Everywhere I use the word "list" you can assume I'm talking about a JS Array) This means, to perform a single operation on the list as a whole ("atomically"), and to return a new list - thus making it much simpler to think about both the old list and the new one, what they contain, and