Skip to content

Instantly share code, notes, and snippets.

View divmgl's full-sized avatar

Dexter Miguel divmgl

  • San Francisco, CA
  • 02:21 (UTC -12:00)
View GitHub Profile
@divmgl
divmgl / vpc.js
Created February 22, 2022 14:12
Smitten VPC Arc Plugin
const aws = require("aws-sdk")
const iam = new aws.IAM()
const ec2 = new aws.EC2()
const securityGroupNames = [
"allow-internal-ingress",
"allow-internal-egress",
"allow-external-egress"
]
@divmgl
divmgl / perm_missing_elem.py
Created March 24, 2017 00:16
Codility.com PermMissingElem 100%/100%
def solution(A):
total = sum(A)
diff = sum(range(1, len(A) + 2))
return abs(diff - total)
@divmgl
divmgl / frogjmp.py
Created March 23, 2017 21:31
Codility.com FrogJmp 100%
import math
def solution(X, Y, D):
return int(math.ceil(float(Y - X) / float(D)))
@divmgl
divmgl / cyclicrotation.py
Created March 23, 2017 21:20
Codility.com CyclicRotation 100%
def solution(A, K):
if len(A) == 0:
return A
for _ in range(K):
A.insert(0, A.pop())
return A
@divmgl
divmgl / oddoccurrencesinarray.py
Last active March 23, 2017 21:11
Codility.com OddOccurrencesInArray 100%/100%
def solution(A):
table = dict()
for num in A:
if not table.get(num):
table[num] = 1
else:
table.pop(num)
return table.keys()[0]
@divmgl
divmgl / binarygap.py
Last active April 8, 2017 09:48
Codility.com BinaryGap 100%
def solution(N):
max = 0
bits = 0
bin = "{0:b}".format(N)
for c in bin:
if c == "0":
bits += 1
if c == "1":
if max < bits:
@divmgl
divmgl / binarygap.c
Created March 23, 2017 20:37
Codility.com BinaryGap 100% in C
long bits = 0;
long max = 0;
void binary(long N) {
if (N > 1) {
binary(N / 2);
}
if (N % 2 == 0) {
bits += 1;
return;
@divmgl
divmgl / random.cpp
Last active January 7, 2017 05:05
Weighted random function
#include <iostream>
#include <array>
#include <map>
#include <random>
using std::cout;
using std::endl;
using std::string;
using std::array;
@divmgl
divmgl / maxcounters.js
Created December 1, 2015 07:23
MaxCounters Javascript Solution 100%/100%
function solution(N, A) {
var M = A.length; // Length of the entry array
var C = []; // Counters
var H = 0; // Highest counter
var PH = 0; // Previously recorded highest counter
for(K = 0; K < N; K++) { // Initialize the array
C[K] = 0;
}
@divmgl
divmgl / missinginteger.js
Created December 1, 2015 06:28
MissingInteger Javascript solution 100%/100%
function solution(A) {
var F = []; // Found list
var I = 0, V = 0; // Counter, container
while (I < A.length) { // Iterate through the array
V = A[I]; // Store the value
I++; // Increase counter
if (F[V]) continue; // If the value exists, continue
F[V] = true; // Store the value
}