Skip to content

Instantly share code, notes, and snippets.

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

J.D Nicholls jdnichollsc

🏠
Working from home
View GitHub Profile
//Copy the collection to prevent deleting data
db.nameCollection.copyTo('newNameCollection')
//See the collections in the database
db.getCollectionNames()
//See if exist duplicate data
db.orders.aggregate([
{
$group: {
var file = fileOrFileArray[i];
if (file.indexOf("data:application") >= 0) {
var fileData = Windows.Security.Cryptography.CryptographicBuffer.decodeFromBase64String(file.split(',')[1]);
var memoryStream = new Windows.Storage.Streams.InMemoryRandomAccessStream();
var dataWriter = new Windows.Storage.Streams.DataWriter(memoryStream);
dataWriter.writeBuffer(fileData);
dataWriter.storeAsync().done(function () {
@jdnichollsc
jdnichollsc / main.js
Created January 17, 2016 19:59
Cordova - Send base64 file with jsPDF and Email Composer
var pdfString = doc.output('datauristring'); //base64 string from jsPDF
if (window.cordova && window.cordova.plugins.email) {
var email = {
//to: 'jdnichollsc@hotmail.com',
//cc: 'jdnichollsc@hotmail.com',
//bcc: ['jdnichollsc@hotmail.com'],
attachments: [
generateAttachment(pdfString, "myFileName.pdf")
@jdnichollsc
jdnichollsc / pdf.js
Created January 17, 2016 20:41
Generate PDF in base64 with jsPDF
services.factory('PDF', ['$q', function ($q) {
var createSubtopic = function (doc, subtopic, top, pageWidth) {
doc.autoTable([
{ title: "Title", dataKey: "title" },
{ title: "Value", dataKey: "value" }
], [
{ title: "Estándar", value: subtopic.standard },
{ title: "Tema", value: subtopic.topic },
@jdnichollsc
jdnichollsc / game.js
Last active February 17, 2016 05:23
Phaser Kinetic Scrolling Plugin - Draft (Swipe and Tap)
var game = new Phaser.Game(1024, 768, Phaser.AUTO, '', {
init: function () {
this.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;
this.scale.pageAlignHorizontally = true;
this.scale.pageAlignVertically = true;
//Load the plugin
this.game.kineticScrolling = this.game.plugins.add(Phaser.Plugin.KineticScrolling);
},
create: function () {
@jdnichollsc
jdnichollsc / examples.md
Last active November 2, 2021 16:13
Git commands

Revertir un commit

  • git revert -m 1

Devolverse a un commit anterior (peligro, va a remover cambios locales)

  • git reset --hard HEAD~1

Subir los cambios a la fuerza

  • git push -f

Cambiar la rama actual

@jdnichollsc
jdnichollsc / fileService.js
Last active May 2, 2016 18:18
Download and Open File with ngCordova in Ionic Framework
(function() {
'use strict';
angular
.module('App')
.factory('Files', Files);
Files.$inject = ['$window', '$cordovaFileTransfer', '$ionicLoading', '$cordovaFileOpener2'];
function Files($window, $cordovaFileTransfer, $ionicLoading, $cordovaFileOpener2) {
return {
@jdnichollsc
jdnichollsc / script.js
Last active May 27, 2016 20:52
Repeat HTTP request removing cookies and localStorage
var foo = function(){
//Clear cookies
var cookies = document.cookie.split(";");
for (var i = 0; i < cookies.length; i++) {
var cookie = cookies[i];
var eqPos = cookie.indexOf("=");
var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
@jdnichollsc
jdnichollsc / app.js
Last active May 8, 2017 18:31
Ionic Google OAuth Authentication, Firebase 3 and (ngCordovaOauth plugin or cordova-plugin-googleplus)
angular.module('App', ['ionic', 'ngCordova', 'ngAnimate', 'ngCordovaOauth', 'firebase'])
.run(['$ionicPlatform',
'$rootScope',
'$firebaseAuth',
function($ionicPlatform, $rootScope, $firebaseAuth) {
$ionicPlatform.ready(function() {
if(window.cordova && window.cordova.plugins.Keyboard) {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
@jdnichollsc
jdnichollsc / assign.js
Last active August 8, 2016 21:40
Accesing Nested Object Properties
var assignProperty = function (object, property, value) {
if (typeof property === "string") {
property = property.split(".");
}
if (property.length > 1) {
var e = property.shift();
assignProperty(object[e] = Object.prototype.toString.call(object[e]) === "[object Object]" ? object[e] : {}, property, value);
} else {
object[property[0]] = value;
}