Skip to content

Instantly share code, notes, and snippets.

View EdmundLeex's full-sized avatar

Edmund Lee EdmundLeex

View GitHub Profile
# I/O Exercises
#
# * Write a `guessing_game` method. The computer should choose a number between
# 1 and 100. Prompt the user to `guess a number`. Each time through a play loop,
# get a guess from the user. Print the number guessed and whether it was `too
# high` or `too low`. Track the number of guesses the player takes. When the
# player guesses the number, print out what the number was and how many guesses
# the player needed.
# * Write a program that prompts the user for a file name, reads that file,
# shuffles the lines, and saves it to the file "{input_name}-shuffled.txt". You
class Board
def initialize(grid = nil)
@grid = grid || Array.new(3, Array.new(3))
end
def grid
@grid.each { |row| p row }
end
class Board
attr_reader :grid
def initialize(grid = nil)
@grid = grid || self.class.default_grid
end
def self.default_grid
Array.new(10) { Array.new(10) }
end
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="\W\[\033[36;1m\]\$(parse_git_branch)\[\033[00m\] $ "
@EdmundLeex
EdmundLeex / cloudinary.rake
Created October 19, 2015 06:49
A rake file for manipulating cloudinary api
namespace :cloudinary do
task :destroy_all => :environment do
public_ids = get_ids
until public_ids.size <= 1
public_ids = get_ids
result = Cloudinary::Api.delete_resources(
public_ids,
cloud_name: ENV['cloud_name'],
api_key: ENV['api_key'],
@EdmundLeex
EdmundLeex / react-drag-n-drop
Created October 20, 2015 08:03
The Simplest Drag n Drop using React.js
var DragNDrop = React.createClass({
// this set the data your want to transfer to the drop-zone
handleDragStart: function (e) {
e.dataTransfer.setData("text", e.target.id);
},
// not important
handleDragEnd: function (e) {
e.preventDefault();
},
# Tools for making inherited interfaces private to a class.
module FigLeaf
module Macros
# Given a list of classes, modules, strings, and symbols, compile
# a combined list of methods. Classes and modules will be queried
# for their instance methods; strings and symbols will be treated
# as method names.
#
# Once the list is compiled, make all of the methods private.
#
class FileDownloader {
func downloadFile(_ fileType: FileType, from urlString: String, as fileName: String, completion: @escaping (String?) -> Void) -> DownloadTask? {
let filePath = LocalStorage.documentPath(of: fileType).appendingPathComponent(fileName)
if !LocalStorage.fileExists(of: fileType, fileName: fileName) {
#if DEBUG
print("file not found at \(filePath)")
#endif
let storage = Storage.storage()
let storageRef = storage.reference(forURL: urlString)
@EdmundLeex
EdmundLeex / find_text.js
Created November 9, 2018 23:09
Finding text on html page.
var all = document.getElementsByTagName("*");
var body;
for (var i = 0; i < all.length; i++) {
if (all[i].tagName === 'BODY') { body = all[i]; break; }
}
function highlightInElement(element, text){
var elementHtml = element.innerHTML;
var tags = [];
var tagLocations= [];