Skip to content

Instantly share code, notes, and snippets.

View primayudantra's full-sized avatar
👋
Hi, Prima here!

Prima Yudantra primayudantra

👋
Hi, Prima here!
View GitHub Profile
@primayudantra
primayudantra / js-mainan.js
Created June 20, 2017 07:41
Basic Simple JS
let _ = require("lodash")
/*
VALIDATION
ODD AND EVEN NUMBER
*/
var a = []
for(var i=0; i < 20; i++){
if(i%2){
@primayudantra
primayudantra / fh.js
Created July 1, 2017 14:24
fh - berlin
let a = [2, 4, 6, 8, 9, 15]
let b = ['4', '16', '64']
function question_1(){
while(b.length > 0){ b.pop(); }
a.concat(b).forEach(function(data){
b.push(data);
})
console.log(b) //print all data b
}
var obj = {
"dataExample": "[{\"usia\":\"7 tahun\",\"kehamilan\":\"Tidak Hamil dan Tidak Menyusui\",\"pendidikan\":\"SD & Sederajat\",\"jenis_kelamin\":\"Laki-laki\",\"maritalstatus\":\"Tidak\",\"$hashKey\":\"object:1224\"},{\"usia\":\"4 tahun\",\"kehamilan\":\"Tidak Hamil dan Tidak Menyusui\",\"pendidikan\":\"Tidak Sekolah\",\"jenis_kelamin\":\"Perempuan\",\"maritalstatus\":\"Tidak\",\"$hashKey\":\"object:1225\"}]"
}
var x = JSON.stringify(obj, null, 4).replace(/\\/g, "");
console.log(x)
@primayudantra
primayudantra / sort-object-properties-by-value.md
Created July 31, 2017 09:14 — forked from umidjons/sort-object-properties-by-value.md
JavaScript: sort object properties by value (numeric or string)

Sort object properties by value (values are text)

I have following object:

var cities={10:'Tashkent', 14:'Karakalpakiya', 16:'Andijan'};

I want sort it by city names, so after sort it should be:

var cities={16:'Andijan', 14:'Karakalpakiya', 10:'Tashkent'};

But I can't sort object properties, instead can convert object into array, then sort items.

@primayudantra
primayudantra / gist:52cd9306349b1bd3543dc90eb976ff94
Created October 17, 2017 12:44 — forked from aodin/gist:9493190
Parsing JSON in a request body with Go
package main
import (
"encoding/json"
"io/ioutil"
"log"
"net/http"
)
type Message struct {
@primayudantra
primayudantra / async.js
Created October 24, 2017 06:28 — forked from bschwartz757/async.js
Async/await function to fetch data from multiple URLs in parallel
/* Client side, works in Chrome 55 and Firefox 52 without transpilation */
//https://blogs.msdn.microsoft.com/typescript/2016/11/08/typescript-2-1-rc-better-inference-async-functions-and-more/
async function fetchURLs() {
try {
// Promise.all() lets us coalesce multiple promises into a single super-promise
var data = await Promise.all([
/* Alternatively store each in an array */
// var [x, y, z] = await Promise.all([
// parse results as json; fetch data response has several reader methods available:
//.arrayBuffer()
@primayudantra
primayudantra / Makefile
Created November 10, 2017 08:16 — forked from border/Makefile
json example in golang
include $(GOROOT)/src/Make.inc
GOFMT=gofmt -spaces=true -tabindent=false -tabwidth=4
all:
$(GC) jsontest.go
$(LD) -o jsontest.out jsontest.$O
format:
$(GOFMT) -w jsontest.go
package main
import (
"fmt"
"io"
"os"
)
var path = "/Users/novalagung/Documents/temp/test.txt"
@primayudantra
primayudantra / upload_demo_html.html
Created November 15, 2017 05:05 — forked from paambaati/upload_demo_html.html
Uploading files using NodeJS and Express 4
<html>
<body>
<form action="/upload" enctype="multipart/form-data" method="post">
<input type="text" name="title">
<input type="file" name="file">
<input type="submit" value="Upload">
</form>
</body>
</html>
@primayudantra
primayudantra / .bashrc
Created November 20, 2017 06:35 — forked from vsouza/.bashrc
Golang 1.5 setup in Mac OSX with HomeBrew. Set `GOPATH` and `GOROOT` variables in zshell or bash.
# Set variables in .bashrc file
# don't forget to change your path correctly!
export GOPATH=$HOME/golang
export GOROOT=/usr/local/opt/go/libexec
export PATH=$PATH:$GOPATH/bin
export PATH=$PATH:$GOROOT/bin