Skip to content

Instantly share code, notes, and snippets.

async function f() {
let promise = new Promise((resolve, reject) => {
setTimeout(() => resolve("done!"), 1000)
});
let result = await promise; // wait till the promise resolves (*)
alert(result); // "done!"
}
loadScript('first.js', function(err,script){
if(err){
//error handling
//fail to load 1st script
}else{
loadScript('second.js', function(err,script){
if(err){
//error handling
//fail to load 2nd script
}else{
function loadScript(src) {
let script = document.createElement('script');
script.src = src;
document.head.append(script);
}
function getData() {
var data;
$.get("example.php", function(response) {
data = response;
});
return data;
}
var data = getData()
console.log("the data is"+data)
// Say "Hello."
console.log("Hello.");
// Say "Goodbye" two seconds from now.
setTimeout(function() {
console.log("Goodbye!");
}, 2000);
// Say "Hello again!"
console.log("Hello again!");
Math.round(new Date().getTime()/1000)+60 // 1548319864 == 2019.01.24 pm5:50
@icehongssii
icehongssii / gist:d7fa6140ea817c35ced5671f1cd13ffb
Created January 14, 2019 02:36 — forked from evnm/gist:d17336bf42e887c6e756
Script to convert milliseconds since epoch to a human-readable timestamp
#!/usr/bin/python
import datetime
import sys
print datetime.datetime.fromtimestamp(float(sys.argv[1])/1000).strftime('%Y-%m-%d %H:%M:%S.%f')
# Go to home directory
cd ~
# You can change what anaconda version you want at
# https://repo.continuum.io/archive/
curl -Ok https://repo.continuum.io/archive/Anaconda3-4.1.1-MacOSX-x86_64.sh
bash Anaconda3-4.1.1-MacOSX-x86_64.sh -b -p ~/anaconda
rm Anaconda3-4.1.1-MacOSX-x86_64.sh
echo 'export PATH="~/anaconda/bin:$PATH"' >> ~/.bash_profile
const app = require('express')();
const server = require('http').Server(app);
const request = require('request');
const io = require('socket.io-client');
server.listen(3005);
app.get('/', function (req, res, err) {
@icehongssii
icehongssii / cexio.js
Created August 16, 2018 02:22
Getting last price from cexio
const app = require('express')();
const server = require('http').Server(app);
const request = require('request');
const Websocket = require('ws');
function getPairs(){
return new Promise((resolve, reject)=>{
request('https://cex.io/api/currency_limits', function(error, res, body){
if (res.statusCode == 200 && !error){