Skip to content

Instantly share code, notes, and snippets.

View didasy's full-sized avatar
🤔
Really makes me think

Andida Syahendar didasy

🤔
Really makes me think
  • Indonesia
View GitHub Profile
@didasy
didasy / mousetrack.js
Created June 26, 2014 02:19
To track a mouse every x seconds
var mouse = { x : 0, y : 0 };
document.addEventListener('mousemove', function (e) {
mouse.x = e.clientX || e.pageX;
mouse.y = e.clientY || e.pageY;
})
var track = function () {
console.log(document.elementFromPoint(mouse.x, mouse.y));
setTimeout(track, 3000);
}
@didasy
didasy / shuffle.go
Created February 12, 2015 16:46
Golang Array Shuffler
/*
An array shuffler with good randomness
*/
package main
import (
"fmt"
"math/big"
"crypto/rand"
)
@didasy
didasy / helpers.go
Last active February 28, 2020 06:36
Golang Slice Helper Functions
/*
A bunch of slice helper functions
All of these modify the original slice
*/
package main
import (
"fmt"
)
# This use wget to download the file with:
# infinite retries
# keep retrying even when there is no connection
# wait 3s between retries
# continue from last point if failed and there is a file named test.file in the target directory
# with limited bandwidth rate of 2 000 000 Bytes/s
# and put the file to the path/filename
wget -t 0 --retry-connrefused --waitretry=3s -c --limit-rate=2000000 --output-document=~/Downloads/test.file http://localhost/file/test.file
@didasy
didasy / FileUpload.js
Last active August 29, 2015 14:16
A piece of code to upload a file to a remote server using HTTP POST with request.js
/*
* Node.js file upload using request.js, the example
* Does not work in Node.js v0.12.x yet @2015-03-05 using [email protected]
* Usage : node FileUpload.js /my/path/to/file.txt http://mysite/upload 10 3000
*/
var fs = require("fs"),
request = require("request"),
filepath = process.argv[2],
targetUrl = process.argv[3],
@didasy
didasy / gpu.js
Created July 4, 2015 13:17
Finding GPU Info via JS
var canvas = $('<canvas />', { width: '1', height: '1' }).appendTo('body');
var webglVersion = window.location.search.indexOf('v=2') > 0 ? 2 : 1;
var gl;
var possibleNames = (webglVersion === 2) ? ['webgl2', 'experimental-webgl2'] : ['webgl', 'experimental-webgl'];
var contextName;
possibleNames.forEach(function (name) {
gl = canvas[0].getContext(name, { stencil : true });
contextName = !!gl;
});
@didasy
didasy / ko.js
Created July 20, 2015 10:52
KnockoutJS Transition Binding
var prevElem = null;
// find out how to put prevElem as property and access it from update function
ko.bindingHandlers.fadeVisible = {
init: function(element, valueAccessor) {
var value = ko.unwrap(valueAccessor());
$(element).toggle(value);
},
update: function(element, valueAccessor) {
var value = ko.unwrap(valueAccessor());
@didasy
didasy / logrotater.go
Created August 3, 2015 07:58
Log rotater boilerplate for log.SetOutput
import (
"os"
"sync"
"time"
)
type RotateWriter struct {
lock sync.Mutex
filename string // should be set to the actual filename
fp *os.File
@didasy
didasy / sample.txt
Created June 8, 2016 08:14
Sample Article
The Miller quick coupler comes in a few different sizes. The one I tried out has the proportions of a laundry bin and weighs nearly 700 pounds. It allows the operators of hydraulic digging machines to switch buckets without ever leaving the cab. Two flanges rise from its sides, supplying it with the Volks­wagen-like curves that inspired its nickname, the Bug. The flanges are drilled clean through with four holes set inside four bosses; beneath the front pair of holes are two upturned latches, like the open ends of two wrenches. Other than its poppy-red color, the device appears to be an ordinary specimen from the menagerie of heavy-duty construction equipment.
But in a Chicago courtroom on Oct. 26, the Bug will star in a multimillion-dollar dispute that represents a new frontier in the march of global capitalism. The nominal occasion is a paternity feud between two of the Bug’s corporate parents, Miller UK, the equipment manufacturer based in Cramlington, England, and Caterpillar, the American construction-e
@didasy
didasy / ring.js
Last active November 11, 2016 08:28
Ring data structrure in JavaScript.
class Ring {
constructor(...data) {
this.position = 0;
if (data instanceof Array) {
this.data = data[0];
return;
}
this.data = data;
}