Skip to content

Instantly share code, notes, and snippets.

@jheth
jheth / gist:271ab8b4ad82b2b07218
Last active August 29, 2015 14:07
Salesforce: Clone QuoteLineItems from Quote
try {
String sourceId = '0Q0i00000019TdOCAU';
String destinationId = null; //'0Q0i00000019TdTCAU';
String query = 'select Quoteid, PricebookEntryId, Quantity, UnitPrice, Discount, Description, ServiceDate, ListPrice, Subtotal, TotalPrice ';
// get all of the custom, writeable fields
Map<String, Schema.SObjectField> fieldMap = QuoteLineItem.getSObjectTypE().getDescribe().fields.getMap();
for (String key : fieldMap.keySet()) {
Schema.SObjectField field = fieldMap.get(key);
Schema.DescribeFieldResult result = field.getDescribe();
if (result.isCustom() && !result.isCalculated()) {
@jheth
jheth / gist:793c512506111e1fd721
Created August 27, 2014 20:04
Load jQuery from Console
var jq = document.createElement('script');
jq.src = "//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);
// ... give time for script to load, then type.
jQuery.noConflict();
@jheth
jheth / gist:8030435
Created December 18, 2013 21:50
Ruby Gem Spec Parsing
# Try to load gem information from spec file. Often fails due to gemspec referencing git commands.
Dir.glob(ENV['GEM_HOME'] + "/**/*.gemspec").each do |spec|
spec = Gem::Specification::load(spec)
if spec
license_file = spec.homepage.to_s.include?("github") ? spec.homepage + "/master/blob/LICENSE" : ''
puts "#{spec.name}, #{spec.version}, #{spec.homepage}, #{spec.license}, #{license_file}"
end
end
# regex for values we care about
<samlp:Response xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
ID="R3fcfe38ecf56858aed1c82e64af35a184365666b" Version="2.0"
IssueInstant="2013-12-14T17:39:06Z" Destination="https://www.hostedservice.com/sso/saml/acs"
InResponseTo="_8dc163f0-4714-0131-0e2a-20c9d04963c9">
<saml:Issuer>https://app.onelogin.com/saml/metadata/XXXXXX</saml:Issuer>
<samlp:Status>
<samlp:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success" />
</samlp:Status>
<saml:Assertion xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@jheth
jheth / AuthnRequest
Last active December 31, 2015 08:39
<?xml version="1.0" encoding="UTF-8"?>
<samlp:AuthnRequest xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
ID="alcoelhllgeljalnmneocaeebekgmboefbnaeehk"
Version="2.0"
IssueInstant="2013-12-14T17:08:02Z"
ProtocolBinding="urn:oasis:names.tc:SAML:2.0:bindings:HTTP-Redirect"
ProviderName="hostedservice.com"
AssertionConsumerServiceURL="https://www.hostedservice.com/sso/saml/acs"/>
@jheth
jheth / gist:5541976
Created May 8, 2013 17:15
I wanted to capture the redirect location for the visual force salesforce domain. This does just that.
curl = Curl::Easy.http_get('https://tinderbox.na15.visual.force.com')
curl.header_str
http_response, *http_headers = curl.header_str.split(/[\r\n]+/).map(&:strip)
http_headers = Hash[http_headers.flat_map{ |s| s.scan(/^(\S+): (.+)/) }]
http_response # => "HTTP/1.1 200 OK"
http_headers["Location"]
@jheth
jheth / gist:5239103
Created March 25, 2013 17:50
Rails mailer configuration for Google Apps
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.default_charset = "utf-8"
ActionMailer::Base.smtp_settings = {
:enable_starttls_auto => true,
:address => "smtp.gmail.com",
:port => "587",
:domain => "domain.com",
:authentication => :login,
@jheth
jheth / wget-recursive-fetch
Last active December 12, 2015 02:08
Fetch Rails Guides using wget
wget --recursive --no-clobber --page-requisites --adjust-extension --convert-links --restrict-file-names=unix --domains guides.rubyonrails.org --no-parent http://guides.rubyonrails.org/v2.3.11/
@jheth
jheth / svn-sed-xargs
Last active December 12, 2015 00:58
Look for new or modified files and check them for coding standard violations.
svn status | grep "^[AM]" | sed "s/^. //" | xargs phpcs
@jheth
jheth / phpunit-example
Last active December 12, 2015 00:58
Sample PHP class and PHPUnit test using a dataProvider.
<?php
class StringUtil
{
public function is_palindrome($str)
{
if (!is_string($str)) {
return false;
}
$length = strlen($str);