Skip to content

Instantly share code, notes, and snippets.

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

Francesco Falanga ceccode

🏠
Working from home
View GitHub Profile
# mongodb.conf
# Note: if you run mongodb as a non-root user (recommended) you may
# need to create and set permissions for this directory manually,
# e.g., if the parent directory isn't mutable by the mongodb user.
dbpath=/usr/local/var/mongodb
#where to log
logpath=/usr/local/var/log/mongodb/mongo.log
// Desired unique index:
// db.collection.ensureIndex({ firstField: 1, secondField: 1 }, { unique: true})
db.collection.aggregate([
{ $group: {
_id: { firstField: "$firstField", secondField: "$secondField" },
uniqueIds: { $addToSet: "$_id" },
count: { $sum: 1 }
}},
{ $match: {
var mongoose = require('mongoose'),
// Load User model
User = mongoose.model('User'),
// Create Thing schema
thingSchema = new mongoose.Schema({
_user: {
type: ObjectId,
@ceccode
ceccode / avg-example.js
Created October 14, 2014 08:18
Get Avg of array using MongoDB MapReduce
db.avgexample.drop();
db.avgexample.insert({"name":"test1", "value": [1,2,3,4]});
db.avgexample.insert({"name":"test1", "value": [5,6,7,8]});
var map = function() {
var sum = 0;
var count = 0;
for (var i = 0; i < this.value.length; i++) {
@ceccode
ceccode / ng-really.js
Last active August 29, 2015 14:14 — forked from asafge/ng-really.js
/**
* A generic confirmation for risky actions.
* Usage: Add attributes: ng-really-message="Are you sure"? ng-really-click="takeAction()" function
*/
angular.module('app').directive('ngReallyClick', [function() {
return {
restrict: 'A',
link: function(scope, element, attrs) {
element.bind('click', function() {
var message = attrs.ngReallyMessage;
@ceccode
ceccode / pb-ion-sure-click.js
Created February 2, 2015 17:51
Ionic framework confirm directive
/**
* Ionic framework confirm directive
* thanks to: https://gist.github.com/asafge
*
* USAGE: pb-ion-sure-title="Confirm" pb-ion-sure-message="Are you sure" pb-ion-sure-click="funtion()"
*/
.directive('pbIonSureClick', ['$ionicPopup','$timeout', function($ionicPopup, $timeout) {
return {
restrict: 'A',
link: function(scope, element, attrs) {
@ceccode
ceccode / wpml_lang_switcher.php
Created June 29, 2015 08:28
WPML lang switcher
<?php
$languages = icl_get_languages('skip_missing=0&orderby=code');
if(!empty($languages)){
$i = 0;
$numItems = count(languages);
foreach($languages as $l){
if(!$l['active']) {
echo '<a href="'.$l['url'].'">';
}
echo $l['language_code'];
@ceccode
ceccode / info.plist
Created October 22, 2015 13:11 — forked from mlynch/info.plist
Disable App Transport Security in iOS 9
<!--
This disables app transport security and allows non-HTTPS requests.
Note: it is not recommended to use non-HTTPS requests for sensitive data. A better
approach is to fix the non-secure resources. However, this patch will work in a pinch.
To apply the fix in your Ionic/Cordova app, edit the file located here:
platforms/ios/MyApp/MyApp-Info.plist
And add this XML right before the end of the file inside of the last </dict> entry:
/**
* ================== angular-ios9-uiwebview.patch.js v1.1.1 ==================
*
* This patch works around iOS9 UIWebView regression that causes infinite digest
* errors in Angular.
*
* The patch can be applied to Angular 1.2.0 – 1.4.5. Newer versions of Angular
* have the workaround baked in.
*
* To apply this patch load/bundle this file with your application and add a
@ceccode
ceccode / wordpress .gitignore
Last active November 9, 2015 16:32 — forked from salcode/.gitignore
WordPress .gitignore
# -----------------------------------------------------------------
# Forked .gitignore for WordPress by @salcode, ver 20150227
#
# ver. 0.1 @ceccode
#
#
# By default all files are ignored. You'll need to whitelist
# any mu-plugins, plugins, or themes you want to include in the repo.
#
# To ignore uncommitted changes in a file that is already tracked, use