Skip to content

Instantly share code, notes, and snippets.

View luishendrix92's full-sized avatar

Luis Felipe López G. luishendrix92

View GitHub Profile
@luishendrix92
luishendrix92 / pusher.dart
Created March 19, 2024 23:06
Dart - Use the HTTP API for Pusher
import 'package:http/http.dart' as http;
import 'package:crypto/crypto.dart';
import 'dart:convert';
class Pusher {
// Replace -us3 with -YOUR_REGION
static String baseUrl = "https://api-us3.pusher.com/apps";
final String appId;
final String appKey;
@luishendrix92
luishendrix92 / bench.ml
Created March 9, 2024 17:47
Measure execution time of a function in milliseconds at runtime
(** [bench work] runs a function [work] and returns the amount of milliseconds
it took to finish. Uses [Sys.time] to mark the start and end of execution. *)
let bench work =
let start_time = Sys.time () in
work ();
let end_time = Sys.time () in
(end_time -. start_time) *. 1000.0
;;
(* Let's give it a test run! *)
@luishendrix92
luishendrix92 / tcase.dart
Created March 4, 2024 16:54
Title Case a String in Dart
String titleCase(String input) {
return input.splitMapJoin(RegExp(r'(\s+|\[|\(|\/)+'),
onMatch: (m) => '${m[0]}',
onNonMatch: (word) {
if (word.length < 2) return word.toUpperCase();
return word.substring(0, 1).toUpperCase() + word.substring(1);
});
}
@luishendrix92
luishendrix92 / .ocamlformat
Created March 3, 2024 06:03
My Ocamlformat
profile = janestreet
version = 0.26.1
margin = 80
exp-grouping = preserve
@luishendrix92
luishendrix92 / rpn.ml
Created February 27, 2024 19:53
Reverse Polish Notation Evaluation
exception RPN_eval
type token =
| Num of float
| Binary of (float -> float -> float)
| Unary of (float -> float)
let eval_rpn tokens =
let rec aux ~stack tokens =
match tokens, stack with
@luishendrix92
luishendrix92 / obs.ml
Last active February 27, 2024 18:18
OCaml Observer Pattern
open Printf
(* Example adapted from the book:
Head First Design Patterns *)
class virtual observer =
object
method virtual update : unit
end
@luishendrix92
luishendrix92 / ocaml.lua
Created February 18, 2024 05:56
Ocaml Snippets from my dotfiles (beta)
local ls = require("luasnip")
local s = ls.snippet
local sn = ls.snippet_node
local t = ls.text_node
local i = ls.insert_node
local f = ls.function_node
local c = ls.choice_node
local d = ls.dynamic_node
-- local rep = require("luasnip.extras").rep
-- local fmt = require("luasnip.extras.fmt").fmt
@luishendrix92
luishendrix92 / aesthetics.js
Last active February 18, 2024 21:52
Vaporwave aesthetic full-width text generator
const vaporwave = str =>
str.split('')
.map(char =>
/\S/i.test(char)
? String.fromCharCode(char.charCodeAt(0) + 65248)
: char)
.join('')
//!> Corporate Aesthetic 80's Shopping Mall
console.log(
@luishendrix92
luishendrix92 / regscan.js
Last active February 20, 2017 06:13
JavaScript RegExp Scan Polyfill
RegExp.prototype.scan = function(text) {
var result = [], match;
while(match = this.exec(text)) {
result.push(match);
}
return result;
};
@luishendrix92
luishendrix92 / cyclic.js
Last active January 31, 2020 19:44
Cyclic Iterator (with ES6 Generators) and .take()
/*
Say I need to iterate over [1, 2, 3], yielding a value
at a time but once I reach the final value, I want to
keep receiving the values over and over again, making
it a repeated sequence: 1, 2, 3, 1, 2, 3, 1 and so on...
*/
const cyclic = list => (function* () {
while (true) for (let item of list) yield item
}())