Skip to content

Instantly share code, notes, and snippets.

@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: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 / Ruby Merge Sort
Created January 25, 2015 03:20
Ruby Merge Sort
def mergesort( a )
n = a.size
return a if ( n == 1 )
l1 = a[0...(n/2)]
l2 = a[(n/2)..n]
l1 = mergesort( l1 )
l2 = mergesort( l2 )
@jheth
jheth / gist:442ee65d9c58e0beaf71
Created February 11, 2015 03:28
Clear Old Session Records
DROP procedure IF EXISTS `ClearSessions`;
DELIMITER $$
CREATE PROCEDURE ClearSessions(IN days_ago INT)
BEGIN
DECLARE bDone INT;
DECLARE count INT;
DECLARE sessionId INT;
@jheth
jheth / gist:22a0e7fb175c1a09c7d6
Created February 20, 2015 21:47
select2 ajax
this.$().select2({
ajax: {
url: "/search",
type: 'GET',
dataType: 'json',
delay: 250,
data: function (term) {
return {
q: term,
id: params.id,
@jheth
jheth / gist:f5e0d2e12ee529092ed5
Last active August 29, 2015 14:17
Dentaku Search
c = Dentaku::Calculator.new
c.add_function(
name: :blank,
type: :logical,
signature: [:non_group],
body: ->(var) {
ap "Value: #{var}"
return (var.to_s.strip.empty?)
}
@jheth
jheth / gist:d49e6a8d010cd700d5d7
Created June 29, 2015 16:15
Delete Folders older than 30 days
find . -maxdepth 1 -type d -ctime +30 -exec rm -rf {} \;
@jheth
jheth / gist:87e1e3e8f80e04da7f0a
Created July 22, 2015 19:43
Port Mapping on Gentoo
sudo /sbin/iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to 8080
sudo /etc/init.d/iptables save
sudo /etc/init.d/iptables start
@jheth
jheth / fizzbuzz.js
Created September 21, 2015 17:34
Javascript Fizz Buzz
for (i = 1; i <= 100; i++) {
var f = (i % 3 == 0);
var b = (i % 5 == 0);
if (f && b) {
console.log('fizzbuzz', i);
} else if (f) {
console.log('fizz', i);
} else if (b) {
console.log('buzz', i);
}
@jheth
jheth / jabber-bot patch
Created July 11, 2012 04:01
Jabber Subscription Request Callback
lib/jabber/bot.rb
204,208d203
< @jabber.roster.add_subscription_request_callback do |item,pres|
< @jabber.roster.accept_subscription(pres.from)
< puts 'accepted request from ' + pres.from.to_s
< end