Skip to content

Instantly share code, notes, and snippets.

View jmahmood's full-sized avatar

Jawaad Mahmood jmahmood

View GitHub Profile
@jmahmood
jmahmood / service.ts
Last active May 3, 2022 21:34
Using JavaScript Generators with Angular2+
// I use generators a lot with python. It seems elegant to me; keep only the data you need and iterate along.
// I was happy to see that they had added generators to JavaScript and had an example where I needed the next 30 days.
// I could put it in an array, but why not try using generators?
// After trial and error, I realized it isn't quite possible in Angular
// Attempt #1: Use Generator function directly in ngFor.
static *next30DaysPlainGenerator = function*(){
const initial_date = new Date();
@jmahmood
jmahmood / ZenkakuHankaku.cls
Created May 30, 2017 01:21
Converting Strings to Zenkaku (全角) or Hankaku (半角) using Salesforce APEX
public class ZenkakuHankaku{
/* The character list retrieved from a JavaScript library, can't find now though. :/ */
public static String toZenkaku(String s) {
if (String.isBlank(s)){
return s;
}
String str = s.replace('\u0020', '\u3000').replace('\u0022', '\u201D').replace('\u0027', '\u2019').replace('\u00A5', '\uFFE5').replace('\uff61', '\u3002').replace('\uff62', '\u300c').replace('\uff63', '\u300d').replace('\uff64', '\u3001').replace('\uff65', '\u30fb').replace('\uff66', '\u30f2').replace('\uff67', '\u30a1').replace('\uff68', '\u30a3').replace('\uff69', '\u30a5').replace('\uff6a', '\u30a7').replace('\uff6b', '\u30a9').replace('\uff6c', '\u30e3').replace('\uff6d', '\u30e5').replace('\uff6e', '\u30e7').replace('\uff6f', '\u30c3').replace('\uff70', '\u30fc').replace('\uff71', '\u30a2').replace('\uff72', '\u30a4').replace('\uff73', '\u30a6').replace('\uff74', '\u30a8').replace('\uff75', '\u30aa').replace('\uff76', '\u30ab').replace('\uff77', '\u30ad').replace('\uff78
@jmahmood
jmahmood / main.go
Created May 15, 2017 16:10
The MANTWON elite hacking program
package main
import (
"fmt"
"os"
"github.com/urfave/cli"
)
func main() {
@jmahmood
jmahmood / throwaway.py
Created April 10, 2017 00:39
Python; learning debugging for the mac
# Creating a debugger on Mac OS using Python and Python CTypes
# ------------------------------------------------------------
# If you are like me, you are following along the Grey Hat Python book that was on the "Humble Bundle" sale and are
# a bit frustrated that everything is about Windows. Also that it requires Python 2.5.
#
# (I haven't used a Windows machine for years and doubt I will be doing dev for it in my career.)
#
# I am trying to implement the Chapter 3 debugger stuff in this file, using Python 3.5.
# This is not necessarily something pythonic or using best practices, I just want to get it working, after which
# I may clean it up.
@jmahmood
jmahmood / Example.cls
Last active July 27, 2016 07:26
Sets vs. Lists in Apex Code in Salesforce.com
// original
public List<selectOption> getSubCategoryEstimate(){
List<selectOption> options = new List<selectOption>();
if(selectedCategory!=null){
List<Material_Grouping_Estimate__c> listSub = new List<Material_Grouping_Estimate__c>();
listSub = [select Category__c , Sub_Category__c from Material_Grouping_Estimate__c WHERE Category__c like :selectedCategory ORDER BY Sub_Category__c];
@jmahmood
jmahmood / dont_do_this.cls
Last active November 7, 2017 05:07
Don't do this in Salesforce please.
// Salesforce attracts programmers that have spent too much time using the same languages
// their whole life, without appropriate 'adventures' into other languages. It shows sometimes.
// IMO APEX doesn't really go out of its way to advertise its various collection types like Python
// or scripting languages & functional languages do. As a result, you end up reinventing the wheel a lot.
// Wrong way, don't do this.
List<Id> LstParentId = new List<Id>();
if (newList != null)
@jmahmood
jmahmood / gist:71de7404943d0912647c
Created May 22, 2015 04:46
Python Django integration with Imgur (For dealing w/ life on Heroku)
import base64
import os
import tempfile
from django.core.exceptions import SuspiciousFileOperation
from django.core.files import File
from django.utils._os import safe_join
import requests
from django.core.files.storage import Storage
@jmahmood
jmahmood / gist:c3e82d07e7190c31c10d
Created May 12, 2015 01:28
How to upload object attachments from SFDC to an external source.
/*
TODO:
- Handle 404s / other errors
- Handle invalid Attachment ids
-
*/
class testUploadAttachment {
@future(callout=true)
import Cocoa
// Load data from a URL.
let url: NSURL = NSURL(string: "http://www.tokyomuslim.com")
let resultsData = NSData(contentsOfURL: url, options: NSDataReadingOptions.DataReadingUncached, error: nil)
let resultsString:NSString = NSString(data: resultsData, encoding: NSUTF8StringEncoding)
// Load JSON data.
let jsonUrl: NSURL = NSURL(string: "https://api.github.com/users/mralexgray/repos/")
let jsonResultsData = NSData(contentsOfURL: jsonUrl, options: NSDataReadingOptions.DataReadingUncached, error: nil)
@jmahmood
jmahmood / gist:6526167
Created September 11, 2013 16:27
Data CD/DVD Backup script
#! /bin/bash
# Wait for a CD to be inserted then copy the contents
#
echo "CD copy, press <ctrl>C to exit"
echo "Looking for disk..."
#
# Go into a continuous loop always looking for a new CD
while :
do