Skip to content

Instantly share code, notes, and snippets.

@Patlatus
Patlatus / c.py
Created April 8, 2018 16:30
My try to problem C of Google Code Jame QR 2018
import sys, copy;
def solve():
return 0;
def getSomeOpenCell(sm, nm, em, wm, m):
result = {}
for i in range(sm-nm+1):
for j in range(em-wm+1):
#print i, j, nm + i, wm + j, m[nm + i][wm + j]
if m[nm + i][wm + j] == 0:
@Patlatus
Patlatus / d.py
Created April 8, 2018 16:31
My try to problem D of Google Code Jame QR 2018
import sys, copy;
import math;
def solve(a):
alpha = math.asin(a*a-1)/2;
print alpha
print math.cos(alpha)/2
print math.sin(alpha)/2
print -math.cos(alpha)/2, math.sin(alpha)/2, .5
print -math.sin(alpha)/2, -math.cos(alpha)/2, .5
@Patlatus
Patlatus / a.py
Created April 16, 2018 19:17
Google Code Jam 2018 QR Problem A
import sys, copy;
def modify(a, i, z, d):
x = a[i]
y = x['v']
m = z['m']
damage = z['d']
print "y=", y
while (y > 0):
x['v'] -= 1
a[i-1]['v'] += 1
@Patlatus
Patlatus / A-input.txt
Created April 16, 2018 19:19
Google Code Jam - QR 2018 - Problem A - sample input file
10
1 CS
2 CS
1 SS
6 SCCSSC
2 CC
3 CSCSS
10000000 CCCCCCCCCCCCCCCCCCCCSSSSSSSSSS
536870911 CCCCCCCCCCCCCCCCCCCCCCCCCCCCCS
268435455 CCCCCCCCCCCCCCCCCCCCCCCCCCCCCS
@Patlatus
Patlatus / b.py
Created April 16, 2018 19:21
Google Code Jame - QR 2018 - problem B (python)
import sys, copy;
def solve(n,v):
parni = []
neparni = []
for i in range(n):
if i % 2 == 0:
parni.append(v[i])
else:
neparni.append(v[i])
@Patlatus
Patlatus / URLService
Created September 11, 2018 08:26
URLService
<!-- <pre>
public class URLService {
@auraEnabled
public static String getBaseURL() {
PageReference pr = new PageReference('/id/' + UserInfo.getOrganizationId() + '/' + UserInfo.getUserId() + '?oauth_token=' + UserInfo.getSessionId() );
System.debug(LoggingLevel.ERROR, '@@@ v: ' + pr.getContent().toString() );
String data = pr.getContent().toString();
Map result = (Map)Json.deserializeUntyped(data);
Map urls = (Map)result.get('urls');
@Patlatus
Patlatus / EmptyValueFilter
Created October 2, 2018 13:10
EmptyValueFilter
public class EmptyValueFilter implements IFilter {
SObjectField field;
public EmptyValueFilter(SObjectField f) {
field = f;
}
public Boolean check(SObject rec, SObject old) {
return rec.get(field) == null
}
}
@Patlatus
Patlatus / MD.apxc
Created October 18, 2018 13:36
MD.apex
public class MD {
public static List<String> getItems(List<String> parts, Map<String, Schema.SObjectField> fieldsMap, SObject r) {
List<String> items = new List<String>();
for (String part: parts) {
items.add( fieldsMap.containsKey( part ) ? String.valueOf( r.get( part ) ) : part );
}
return items;
}
public static Id updateAndDeployMetadata(List<SObject> sourceRecords, SObjectType dest, Map<SObjectField, SObjectField> mappings, String fullNameDef, String labelDef) {
Metadata.DeployContainer mdContainer = new Metadata.DeployContainer();
@Patlatus
Patlatus / MD.updateAndDeployMetadata.anon
Created October 18, 2018 13:37
Anon.apex to convert custom object records into custom metadata records
MD.updateAndDeployMetadata(
[ SELECT Field1__c, Field2__c, Field3__c, Field4__c FROM Object__c   ],
CustomMetadata__mdt.sObjectType,
new Map<SObjectField, SObjectField>{
Object__c.Field1__c=> CustomMetadata__mdt.Field1__c,
Object__c.Field2__c=> CustomMetadata__mdt.Field2__c,
Object__c.Field3__c=> CustomMetadata__mdt.Field3__c,
Object__c.Field4__c => CustomMetadata__mdt.Field4__c
},
'X+Field1__c+_+Field2__c',
@Patlatus
Patlatus / buildPackageXMLForMD
Created October 19, 2018 13:48
buildPackageXMLForMD
public static String buildPackageXMLForMD(SObjectType mdt){
String mdtName = mdt.getDescribe().getName();
List<SObject> records = Database.query('SELECT DeveloperName FROM ' + mdt );
List<String> items = new List<String>();
for (SObject r: records) {
items.add( mdtName + '.' + r.get( 'DeveloperName' ) );
}
return ' <types>\r\n <members>' + String.join( items, '</members>\r\n <members>' ) + '</members>\r\n <name>CustomMetadata</name>\r\n </types>';
}