Skip to content

Instantly share code, notes, and snippets.

@samuel-alves
samuel-alves / MyActivity.java
Created September 28, 2016 08:40 — forked from ErikHellman/MyActivity.java
Simple LocalBinder demo for Android
package se.hellsoft.simpleservicecallbackdemo;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
@samuel-alves
samuel-alves / script-loaded.js
Created February 9, 2017 14:10 — forked from AllThingsSmitty/script-loaded.js
Check if any given script has loaded
var myScript = document.createElement('script');
myScript.src = 'http://code.jquery.com/jquery-2.1.4.min.js';
myScript.onload = function() {
console.log('jQuery loaded.');
};
document.body.appendChild(myScript);

Swipe Controls with Backbone.js

Requires

Hammer.js

@samuel-alves
samuel-alves / better-nodejs-require-paths.md
Created March 7, 2017 10:23 — forked from branneman/better-nodejs-require-paths.md
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

var Article = require('../../../models/article');

Those suck for maintenance and they're ugly.

Possible solutions

export ORG_ALIAS='DummyScratchOrg'
export PROJECT_NAME='DummyProject'
export PERMISSION_SET='DummyPermSet'
export IMPORT_PLAN='Dummy-plan.json'
# Create a Salesforce DX project
sfdx force:project:create -n $PROJECT_NAME
# Regist development/sandbox org
sfdx force:auth:web:login [-d] -a $ORG_ALIAS
@samuel-alves
samuel-alves / nodejs-custom-es6-errors.md
Created November 15, 2017 10:56 — forked from slavafomin/nodejs-custom-es6-errors.md
Custom ES6 errors in Node.js

Here's how you could create custom error classes in Node.js using latest ES6 / ES2015 syntax.

I've tried to make it as lean and unobtrusive as possible.

Defining our own base class for errors

errors/AppError.js

@samuel-alves
samuel-alves / remove-pending-crontriggers.cls
Last active January 30, 2018 11:04
Abort scheduled jobs. #salesforce #apex
List<CronTrigger> listCronTrigger = [select Id, CronExpression, EndTime, NextFireTime, OwnerId, PreviousFireTime, StartTime, State, TimesTriggered, TimeZoneSidKey from CronTrigger where State = 'Waiting' or State='Running'];
System.debug('No of jobs: '+listCronTrigger.size());
if (listCronTrigger.size() > 0) {
for (Integer i = 0; i < listCronTrigger.size(); i++){
System.abortJob(listCronTrigger[i].Id);
System.debug('Job details ::'+String.valueOf(listCronTrigger[i]));
}
}
@isTest static void User_can_get_contact_email()
{
// Arrange
System.runAs(createUser())
{
// Act
// Assert
system.assertEquals('[email protected]', contact.Email, 'Email does not match');
}
var Books = Backbone.Collection.extend({
// Lets create function which will return the custom URL based on the method type
getCustomUrl: function (method) {
switch (method) {
case 'read':
return 'http://localhost:3000/api/Books/' + this.id;
break;
case 'create':
return 'http://localhost:3000/api/Books';
break;
@samuel-alves
samuel-alves / uri.js
Created April 13, 2018 10:00 — forked from jlong/uri.js
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"