Skip to content

Instantly share code, notes, and snippets.

View mircoc's full-sized avatar

Mirco Cipriani mircoc

  • Italy
  • 01:54 (UTC +01:00)
View GitHub Profile
@mircoc
mircoc / firstThatCompleteSuccessfullyES6.js
Last active December 13, 2017 14:17
getFirstPromiseThatCompleteSuccessfullyWithinTimeoutES6: Race two or more promises returning the one that finish first and waiting a maximum amount of time. Raw
const firstThatCompleteSuccessfullyES6 = (options) => {
// return the first promise that resolve
const oneSuccess = (promises) => Promise.all(promises.map(p => {
// If a request fails, count that as a resolution so it will keep
// waiting for other possible successes. If a request succeeds,
// treat it as a rejection so Promise.all immediately bails out.
return p.then(
(val) => { return Promise.reject(val); },
(err) => { return Promise.resolve(err); }
@bbshih
bbshih / momentMock.js
Last active February 22, 2023 18:27 — forked from lededje/gist:44aeddf1dc2a5e6064e3b29dc35a7a2d
Jest Mocking Moment to same time zone for tests
// To mock globally in all your tests, add to setupTestFrameworkScriptFile in config:
// https://facebook.github.io/jest/docs/en/configuration.html#setuptestframeworkscriptfile-string
jest.mock('moment', () => {
const moment = require.requireActual('moment-timezone');
moment.tz.setDefault('America/Los_Angeles'); // Whatever timezone you want
return moment;
});
@btroncone
btroncone / rxjs_operators_by_example.md
Last active March 9, 2026 12:54
RxJS 5 Operators By Example
@burtyish
burtyish / page-visibility-service.js
Last active September 19, 2019 20:55
Page Visibility Service for a Redux/Flux app
/* Based on http://www.html5rocks.com/en/tutorials/pagevisibility/intro/ */
class PageVisibilityService {
constructor(store) {
this.store = store;
this.prop = this.getHiddenProp();
this.register();
}
getHiddenProp(){
var path = require('path'),
fs = require('fs');
//this node modules will be require from cordova-lib in main function
var shell;
module.exports = function(context) {
//global module to be share globally in this module
shell = context.requireCordovaModule('shelljs');
@dashohoxha
dashohoxha / install_wifi_access_point.sh
Last active June 7, 2024 18:03
How to setup a Wifi Access Point on Ubuntu 12.04 (or its derivatives).
#!/bin/bash
### Setup a wifi Access Point on Ubuntu 12.04 (or its derivatives).
### make sure that this script is executed from root
if [ $(whoami) != 'root' ]
then
echo "
This script should be executed as root or with sudo:
sudo $0
"
@csanz
csanz / encrypt_decrypt.js
Created August 30, 2011 16:06
Simple String Encryption & Decryption with Node.js
function encrypt(text){
var cipher = crypto.createCipher('aes-256-cbc','d6F3Efeq')
var crypted = cipher.update(text,'utf8','hex')
crypted += cipher.final('hex');
return crypted;
}
function decrypt(text){
var decipher = crypto.createDecipher('aes-256-cbc','d6F3Efeq')
var dec = decipher.update(text,'hex','utf8')
//
// Regular Expression for URL validation
//
// Author: Diego Perini
// Created: 2010/12/05
// Updated: 2018/09/12
// License: MIT
//
// Copyright (c) 2010-2018 Diego Perini (http://www.iport.it)
//