Skip to content

Instantly share code, notes, and snippets.

@swapnilshrikhande
swapnilshrikhande / util.getKeys
Created October 22, 2014 10:07
javascript get all keys for an object.
var util = util || {};
util.getKeys = function (obj) {
var r = []
for (var k in obj) {
if (!obj.hasOwnProperty(k))
continue
r.push(k)
}
return r;
@swapnilshrikhande
swapnilshrikhande / CORS_using_SF_PROXY
Created November 11, 2014 11:59
CORS_using_SF_PROXY
var credential = ' OAuth ' + "<session id of target org >"; // native VF function
var apiUrl = "https://ap1.salesforce.com/services/data/v26.0/chatter/users/me";
$.ajax({
type: "GET",
// for community pages, use whole community url including path, e.g.
// https://logan.blitz01.t.force.com/customers/services/proxy.
url: "https://na9.salesforce.com/services/proxy",
contentType: 'application/json',
cache: false,
success : function(response) {
@swapnilshrikhande
swapnilshrikhande / sObjectSort.java
Last active August 29, 2015 14:09
Generic SObject Sort Method
public static List<Sobject> sort(List<Sobject> sourceList,String fieldName){
List<Sobject> sortedList = new List<Sobject>();
List<SObjectWrapper> wrapperList = new List<SObjectWrapper>();
for(Sobject object : sourceList){
SObjectWrapper wrapperObject = new SObjectWrapper(object,fieldName);
wrapperList.add(wrapperObject);
@swapnilshrikhande
swapnilshrikhande / closureDemo
Last active August 29, 2015 14:09
Demonstrate Closure
function closureParentFunction(){
var localVar = 0;
var localFunction = function(){
console.log('localVar=',++localVar);
}
setInterval(localFunction,2000);
@swapnilshrikhande
swapnilshrikhande / groupDeleteOnBackspace.js
Last active August 29, 2015 14:10
group Delete On Backspace
var BKSPKEY = 8;
handleCommandDelete = function(event,component){
var messageBox = $(component);
var valueText = messageBox.val();
//get current cursor position
if(event.keyCode != BKSPKEY){
return true;
}
@swapnilshrikhande
swapnilshrikhande / bubblesort.js
Last active August 29, 2015 14:10 — forked from bencevans/gist:4117847
bubblesort.js
function bubbleSort (sortingArray) {
var goto = sortingArray.length - 1;
for(var key in sortingArray) {
for(var i = 0; i <= goto - 1; i++) {
if(sortingArray[i] > sortingArray[i + 1]) {
// Swap
var temp = sortingArray[i];
sortingArray[i] = sortingArray[i +1];
sortingArray[i + 1] = temp;
}
@swapnilshrikhande
swapnilshrikhande / machineProblemNSoln.c
Last active August 29, 2015 14:10
Faulty machine problem
#include <stdio.h>
int nextprime(int number);
int isprime(int value);
int main(void)
{
// let size of each choc. be 50 grm
long int chocw=50;
long int expectedw=0;
long int resultw=0;
/*
This game is for Unix only.
It is a simple yet easily navigable Tic-Tac-Toe game for the Unix terminal. To run this file, go
to your awesome Unix terminal and (after you have downloaded this text file, of course) and
navigate to this file. Then, compile and link the program with your handy compiler which will
almost definitely be installed unless you have removed it using the command 'gcc TicTacToe.c'.
This creates an executeable. To run it, you can simply type './a.out'. If you want to have a more
memorable file and/or prevent conflicts, simply change the name with the 'mv' tool
('mv a.out TicTacToe') or use the '-o' ("output file") when compiling
@swapnilshrikhande
swapnilshrikhande / showMessage.html
Last active August 29, 2015 14:10
showMessage.js
<style>
/*Popup message boxes css*/
/*Message boxes*/
.message-box{
position: fixed;
top:2%;
left: 40%;
/*width: 40%;*/
border: 1px solid;
//get all objects
Map<String, Schema.SObjectType> objects = Schema.getGlobalDescribe();
Schema.DescribeSObjectResult objInfo = null;
for (Schema.SObjectType obj : objects.values()) {
objInfo = obj.getDescribe();
System.debug(objInfo.getName() + ' [' + objInfo.getLabel() + ']');
}
//get all fields for account object