Skip to content

Instantly share code, notes, and snippets.

Avatar

Madis Nõmme madis

View GitHub Profile
@madis
madis / approval-transfer-from.cljs
Last active Jul 21, 2021
Debugging ERC20 approval & transferFrom flow in ClojureScript
View approval-transfer-from.cljs
; To run in Ethlance repl
; 1. ./bin/repl
; 2. (shadow/repl :dev-server)
; 3. (in-ns 'ethlance.server.contract.ethlance)
(require '[cljs-web3-next.eth :as web3-eth])
(require '[cljs.core.async :refer [go <!]])
(require '[district.server.web3 :refer [web3]])
(require '[district.shared.async-helpers :refer [<?]])
(require '[ethlance.shared.smart-contracts-dev :as addresses])
@madis
madis / callbacks-to-async-channels.cljs
Created Jul 3, 2021
Converting callbacks to async channels
View callbacks-to-async-channels.cljs
(ns kanalid.core
; (:require-macros [cljs.core.async.macros :refer [go go-loop]])
(:require [cljs.core.async :refer [go <! put!] :as async]
["events" :as EventEmitter]))
(def global-emitter (new EventEmitter))
(defn emit [event data]
(.emit global-emitter event data))
View track-study.sh
#!/usr/bin/env bash
function check_arguments() {
if [ -z "$1" ]
then
echo "No argument supplied"
echo " Usage : ./track-study.sh <seconds to study>"
echo " Example: ./track-study.sh 10"
exit
fi
@madis
madis / callback_server.rb
Last active Mar 14, 2019
Simple Webrick server for testing callbacks in ruby tests
View callback_server.rb
require 'webrick'
require 'rack'
require 'rack/query_parser'
class CallbackServer
ENDPOINT = '/callbacks'
attr_reader :requests
def initialize
View palindrome.rb
#!/usr/bin/env ruby
# You can try the running code at http://tpcg.io/FnffuR
# More explicit implementation. The algorithm you described:
# iterating over characters from both ends of string.
# Returning false as soon as first mismatch is found
def palindrome_by_manual_reversing?(word)
word_string = word.to_s
# Return early because a word is always a palindrome if
@madis
madis / clojars_org_dependencies.md
Created Aug 20, 2017
CodeMode with Madis clojars.org dependencies
View clojars_org_dependencies.md
@madis
madis / serve.rb
Last active Jul 4, 2017
Simple Webrick server
View serve.rb
#!/usr/bin/env ruby
require 'webrick'
class Servlet < WEBrick::HTTPServlet::FileHandler
PORT = 4200
INDEX_FILE = 'index.html'
ROOT_PATH = File.expand_path(__dir__) # Folder of current file
def do_GET(request, response)
View complete_graph.rb
#!/usr/bin/env ruby
class GraphGenerator
# Returns list of edges for n-vertex complete graph
#
# Example:
# GraphGenerator.generate(4)
# [1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4]
def self.generate(count)
if count == 1
@madis
madis / copy_over_ssh.sh
Created Oct 20, 2016
Copy multiple small files from remote machine using ssh & tar
View copy_over_ssh.sh
# From http://meinit.nl/using-tar-and-ssh-to-efficiently-copy-files-preserving-permissions
ssh user@machine-where-precious-data-is "tar czpf - /some/important/data" | tar xzpf - -C /new/root/directory