Skip to content

Instantly share code, notes, and snippets.

View SHEHANhasintha's full-sized avatar
🏠
Working from home

SHEHANhasintha

🏠
Working from home
View GitHub Profile
{
"cmd": ["g++.exe", "-std=c++14", "-o", "$file_base_name", "$file", "&&", "start", "cmd", "/c", "$file_base_name & echo. & echo. & pause"],
"shell": true,
"selector": "source.c++"
}
@SHEHANhasintha
SHEHANhasintha / async-foreach.js
Created October 16, 2018 09:35 — forked from Atinux/async-foreach.js
JavaScript: async/await with forEach()
const waitFor = (ms) => new Promise(r => setTimeout(r, ms))
const asyncForEach = (array, callback) => {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array)
}
}
const start = async () => {
await asyncForEach([1, 2, 3], async (num) => {
await waitFor(50)
@xhacker
xhacker / build-and-run-cpp-st3.md
Last active October 8, 2020 10:52
Build and run C++ file in Sublime Text 3

How to Install

  • Tools → Build System → New build system...
  • Paste the content below
{
    "cmd": ["g++ ${file} -o ${file_path}/${file_base_name} && echo 'Build Finished' && ${file_path}/${file_base_name}"],
    "shell" : true
}
  • Save as C++ Build and Run.sublime-build
@tedmiston
tedmiston / nodejs-tcp-example.js
Last active February 19, 2024 21:55
Node.js TCP client and server example
/*
In the node.js intro tutorial (http://nodejs.org/), they show a basic tcp
server, but for some reason omit a client connecting to it. I added an
example at the bottom.
Save the following server in example.js:
*/
var net = require('net');
@jonathanstark
jonathanstark / adding-js-programmatically.html
Last active September 29, 2021 06:48
Snippet of javascript code that will append external script files programmatically, and in order. Intended for responsive web sites where maximum progressive enhancement is desired. Don't want to make needless http requests or load external javascript on devices that can't (or shouldn't) execute javascript. Any questions/comments/suggestions gre…
<html>
<head></head>
<body>
<!-- All your kewl content goes here -->
<!-- Append javascript programatically so we don't make needless http requests -->
<script>
(function(doc){
var appendScripts = function(srcs) {
@graylikeme
graylikeme / gist:867848
Created March 13, 2011 03:55
fetch images with xhr
<!DOCTYPE html>
<html>
<head>
<title>Kitten!</title>
<meta charset="utf-8" />
<script type="text/javascript">
var xhr = new XMLHttpRequest();
xhr.open('GET', 'http://example.com/images/kitten.jpg', true);