Skip to content

Instantly share code, notes, and snippets.

View rhlsthrm's full-sized avatar
🚀
Shipping

Rahul Sethuram rhlsthrm

🚀
Shipping
View GitHub Profile
@rhlsthrm
rhlsthrm / SwiftAsyncAwaitExample.swift
Last active January 31, 2019 03:20
Using PromiseKit and AwaitKit to write synchronous looking async code.
import PromiseKit
import AwaitKit
struct Todo: Decodable {
var userId: Int
var id: Int
var title: String
var completed: Bool
}
@rhlsthrm
rhlsthrm / SwiftCallbackHell.swift
Last active May 29, 2020 18:55
Swift code to use raw Grand Central Dispatch to make requests
import Foundation
var todos = [String: Any]()
let dispatchGroup = DispatchGroup()
for todo in 0..10 {
let url = URL(string: "https://jsonplaceholder.typicode.com/todos/\(todo)")
dispatchGroup.enter()
let task = URLSession.shared.dataTask(with: url!) { (data, response, error) in
@rhlsthrm
rhlsthrm / ReentrancyToken.sol
Created October 9, 2018 17:18
Fake ERC20 token that recreates reentrancy attack
pragma solidity ^0.4.23;
import "./HumanStandardToken.sol";
import "../../LedgerChannel.sol";
contract ReentrancyToken is HumanStandardToken {
LedgerChannel ledgerChannel;
uint256 constant MAX_REENTRIES = 5;
uint256 numReentries = 0;
@rhlsthrm
rhlsthrm / tedious.js
Created July 27, 2018 00:20
Example of creating and awaiting Promise in Node
// return a promise so you can await it
function Insert_Machine(msg, callback) {
var result = [];
var connection = new Connection(machine_config);
return new Promise(function(resolve, reject) {
connection.on("connect", function(err) {
var request = new Request( // set up request structure
"INSERT INTO dbo.Data_new (pp_id, d_No, d_Note, d_Data, d_seq, d_machine, d_DateTime) OUTPUT INSERTED.Id VALUES (@pp_id, @d_No, @d_Note, @d_Data, 0, @d_machine, @d_DateTime);",
function(err, rowCount) {
if (err) {
@rhlsthrm
rhlsthrm / insertIntoZohoCRM.js
Created December 15, 2017 19:03
Node Express API endpoint code to insert records into Zoho CRM. Use library to generate XML and properly encode.
const axios = require('axios')
const xml = require('xml')
const { asyncRequest } = require('../util')
const { getModels } = require('../models')
const querystring = require('querystring')
const handler = async (req, res) => {
const { MailingList } = getModels()
const { email } = req.body

Keybase proof

I hereby claim:

  • I am rhlsthrm on github.
  • I am rhlsthrm (https://keybase.io/rhlsthrm) on keybase.
  • I have a public key ASAQ4qooOAk2XGA9jkZO4Jf-Cz18h2tZ3hhb1IoeF2VQzQo

To claim this, I am signing this object:

  • Working genesis.json:

`{ "config": { "chainId": 15, "homesteadBlock": 0, "eip155Block": 0, "eip158Block": 0 }, "alloc": {},

@rhlsthrm
rhlsthrm / bracket_validator.py
Created July 11, 2017 21:26
Validates that brackets are properly aligned
def bracket_validator(arg):
openers = []
for char in arg:
if char == '(':
openers.append('paren')
elif char == '{':
openers.append('curly')
elif char == '[':
openers.append('square')
elif char == ')':
service: bittman
provider:
name: aws
runtime: nodejs4.3
environment:
DYNAMODB_TABLE: ${self:service}-${opt:stage, self:provider.stage}
iamRoleStatements:
- Effect: Allow
Action: