Skip to content

Instantly share code, notes, and snippets.

View aindong's full-sized avatar
🎯
Focusing

Alleo Indong aindong

🎯
Focusing
View GitHub Profile
$.ajax({
url: 'http://127.0.0.1:5984/insightout/_all_docs?include_docs=true&limit=25',
type: 'GET',
success: function(result) {
var result = JSON.parse(result);
for(var i = 0; i<result.rows.length; i++) {
if(result.rows[i].doc.type == 'DeviceReading') {
//console.log(result.rows[i].doc._id)
$.ajax({
url: 'http://127.0.0.1:5984/insightout/_design/update_readings/_update/in-place-query/' + result.rows[i].doc._id + '?field=couchDbId&value=19fc40f327d2a154a1c6288089cb7579',
@aindong
aindong / WeekNumber.js
Last active March 23, 2017 16:08
Get the week number of a selected date
// Hacking javascript to get the week number of a selected date
Date.prototype.getWeek = function() {
var date = new Date(this.getTime());
date.setHours(0, 0, 0, 0);
// Thursday in current week decides the year.
date.setDate(date.getDate() + 3 - (date.getDay() + 7) % 7);
// January 4 is always in week 1.
var week1 = new Date(date.getFullYear(), 0, 4);
// Adjust to Thursday in week 1 and count number of weeks from date to week1.
return 1 + Math.round(((date.getTime() - week1.getTime()) / 86400000
@aindong
aindong / SortArrayObject.js
Created December 2, 2014 01:32
Sort an array of object by passing a value
function dynamicSort(property) {
var sortOrder = 1;
if(property[0] === "-") {
sortOrder = -1;
property = property.substr(1);
}
return function (a,b) {
var result = (a[property] < b[property]) ? -1 : (a[property] > b[property]) ? 1 : 0;
return result * sortOrder;
}
@aindong
aindong / EnterOnGrid.cs
Created December 3, 2014 08:21
Listen for the enter key and move on the next column or row on datagridview
protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData)
{
try
{
int icolumn = dgvCart.CurrentCell.ColumnIndex;
int irow = dgvCart.CurrentCell.RowIndex;
if (keyData == Keys.Enter)
{
if (icolumn == dgvCart.Columns.Count - 1)
@aindong
aindong / InstallComposer
Created December 16, 2014 06:39
Install Composer Globally
curl -s http://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/
alias composer='/usr/local/bin/composer.phar'
@aindong
aindong / recursiveRequest.js
Last active August 29, 2015 14:16
Recursive ajax request (polling)
var checkForNewReading = function () {
$.ajax({
url: location.href + '/request',
type: 'GEt',
dataType: 'json',
success: function(data) {
if (data) {
// DO SOMETHING
}
checkForNewReading();
@aindong
aindong / fix
Created March 17, 2015 13:24
Fixed a partitioned(shrinked) in size USB
The command line procedure is not simple, but it is the most likely thing to work.
When re-formatting the "drive" you're actually only formatting a partition on the drive. You need to use the diskpart utility to remove the partitions and create 1 single partition covering the full volume.
diskpart can be a bit dangerous, because if you pick the wrong disk or partition, you can remove data or partitions that are extremely, EXTREMELY important and lose all data on your machine.
Proceed with extreme caution!
Open up a command prompt as administrator (open the start menu, type cmd and press Enter.)
@aindong
aindong / toggleFullScreen.js
Last active August 29, 2015 14:17
Toggle Fullscreen mode on a webpage
function toggleFullScreen() {
if ((document.fullScreenElement && document.fullScreenElement !== null) ||
(!document.mozFullScreen && !document.webkitIsFullScreen)) {
if (document.documentElement.requestFullScreen) {
document.documentElement.requestFullScreen();
} else if (document.documentElement.mozRequestFullScreen) {
document.documentElement.mozRequestFullScreen();
} else if (document.documentElement.webkitRequestFullScreen) {
document.documentElement.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
}
@aindong
aindong / DynamicSetterGetter.php
Created April 16, 2015 15:47
Dynamic setter/getter using __call magic method of php
<?php
class Person
{
protected $firstName;
protected $lastName;
/**
* Magic method call for setter and getter
*
* @param $methodName
@aindong
aindong / jqueryui.autocomplete.extension.js
Created June 3, 2015 02:13
Jquery UI autocomplete select extension
(function( $ ) {
$.ui.autocomplete.prototype.options.autoSelect = true;
$( ".ui-autocomplete-input" ).live( "blur", function( event ) {
var autocomplete = $( this ).data( "autocomplete" );
if ( !autocomplete.options.autoSelect || autocomplete.selectedItem ) { return; }
var matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( $(this).val() ) + "$", "i" );
autocomplete.widget().children( ".ui-menu-item" ).each(function() {
var item = $( this ).data( "item.autocomplete" );