Skip to content

Instantly share code, notes, and snippets.

View turlockmike's full-sized avatar

Michael Darmousseh turlockmike

View GitHub Profile
@turlockmike
turlockmike / contract-created.ts
Last active September 12, 2023 19:11
Event Handlers
//filepath: src/handlers/messages/contract-created.ts
import {vaidationMiddleware} from '@helloextend/api-utils'
//Handle a single Cloud Event.
function contractCreatedHandler(ev: CloudEvent, ctx: Context) {
const messageBody = JSON.parse(ev.message.body) //Or something. Whatever the cloudEvent specification says
const isRetry = ctx.get<number>('event.metadata.retries') > 0
function addMonths(date: Date, months: number): Date {
const newDate = new Date(date)
const dayOfMonth = newDate.getDate()
// The JS Date object supports date math by accepting out-of-bounds values for
// month, day, etc. For example, new Date(2020, 1, 0) returns 31 Dec 2019 and
// new Date(2020, 13, 1) returns 1 Feb 2021. This is *almost* the behavior we
// want except that dates will wrap around the end of a month, meaning that
// new Date(2020, 13, 31) will return 3 Mar 2021 not 28 Feb 2021 as desired. So
// we'll default to the end of the desired month by adding 1 to the desired
8:20:41 PM: Build ready to start
8:20:42 PM: build-image version: 84aca9ba39e0ee86ba194760fbfc51a808f62543
8:20:42 PM: buildbot version: 1ac64ca11e029436ed45ac81a38b9839778ec314
8:20:43 PM: Fetching cached dependencies
8:20:43 PM: Starting to download cache of 129.9MB
8:20:45 PM: Finished downloading cache in 2.548835358s
8:20:45 PM: Starting to extract cache
8:20:51 PM: Finished extracting cache in 5.456247149s
8:20:51 PM: Finished fetching cache in 8.116293732s
8:20:51 PM: Starting to prepare the repo for build
@turlockmike
turlockmike / forms.js
Last active November 17, 2017 22:58
Forms SDK Ideas
//Example in powerforms for example
var el = $("#form");
var data = RetrieveFormData();
forms = new FormSDK(el, data);
forms.Start().then(function(results) {
if (results.age > 50) {
var GAME_CONFIG = {debugMode: false}; //Put some stuff here
var GRAPHICS_CONFIG = {width: 680, height: 400};
var GAME_DATA_FOLDER = "/game_data";
function main() {
//Initialize Components
Game game = new Game(GAME_CONFIG);
GraphicsEngine engine = new SDLGraphicsEngine(GRAPHICS_CONFIG);
GameData assets = new GameData(GAME_DATA_FOLDER);
@turlockmike
turlockmike / routes.rb
Last active August 29, 2015 14:19
Redirect any path ending in .html to the same path without the .html
Rails.application.routes.draw do
get '(*path).html', to: redirect('%{path}')
post '(*path).html', to: redirect('%{path}')
#......
end
@turlockmike
turlockmike / gist:e441a32bf59f6e3c1544
Last active May 23, 2017 17:33
AES-256-CBC encryption with 0 byte padding that works with mcrypt
require 'openssl'
class Encryption
attr_accessor :key
IV_SIZE = 16
def initialize(keycode)
md5 = Digest::MD5.new
md5.update(keycode)
@turlockmike
turlockmike / hash.rb
Created September 10, 2014 19:20
Transform Values in a nested hash
class Hash
def self.transform_values(node,&block)
if node.class == Hash
Hash[node.map{|k,v| [k,Hash.transform_values(v, &block)]}]
else
block.call(node)
end
end
def transform_values(&block)
FB.Event.subscribe("auth.authResponseChange", function(response) {
Octane.facebookAuthStatusUpdate(response.status);
});
FB.getLoginStatus(function(response) {
Octane.facebookAuthStatusUpdate(response.status);
})