Skip to content

Instantly share code, notes, and snippets.

View ahmadina's full-sized avatar
🎯
Focusing

Ahmad ahmadina

🎯
Focusing
View GitHub Profile
<?php
/**
* Ahmad Karimpour <[email protected]>
*
* Created_at 2012
*
* Class Enum
*/
class Enum
@ahmadina
ahmadina / pm2.json
Last active December 15, 2019 09:26
using PM2 for run ES6 (babel) application
{
"apps": [{
"name": "Application",
"exec_interpreter": "./node_modules/babel-cli/bin/babel-node.js",
"script": "./bin/www",
"args": [],
"watch": ["public", "package.json", "pm2.development.json"],
"ignore_watch": ["public"],
"watch_options": {
"persistent": true,
@ahmadina
ahmadina / gist:69dbcd8114341591b3f48f31bff17777
Created July 12, 2016 16:23
Stop / Remove all Docker containers
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
@ahmadina
ahmadina / monitorEvents.js
Created October 19, 2016 08:02 — forked from PaulKinlan/monitorEvents.js
monitorEvents.js
function monitorEvents(element) {
var log = function(e) { console.log(e);};
var events = [];
for(var i in element) {
if(i.startsWith("on")) events.push(i.substr(2));
}
events.forEach(function(eventName) {
element.addEventListener(eventName, log);
});
@ahmadina
ahmadina / webcam.rb
Created September 28, 2017 20:22
using webcam with OpenCV
#!/usr/bin/env ruby
require 'opencv'
include OpenCV
FPS = 30
input = CvCapture.open
win = GUI::Window.new 'video'
loop do
@ahmadina
ahmadina / should_have_attr_accessor.rb
Last active October 3, 2017 12:48
RSpec attr accessor check
RSpec::Matchers.define :have_attr_accessor do |field|
match do |klass|
klass.respond_to?(field) && klass.respond_to?("#{field}=")
end
failure_message do |klass|
"expected attr_accessor for #{field} on #{klass}"
end
failure_message_when_negated do |klass|
@ahmadina
ahmadina / ReconnectingWebSocketProvider.ts
Created August 2, 2023 21:05
Ether.js Reconnecting WebSocket Provider
import { providers } from 'ethers';
const EXPECTED_PONG_BACK = 15000;
const KEEP_ALIVE_CHECK_INTERVAL = 7500;
// Used to "trick" TypeScript into treating a Proxy as the intended proxied class
export const fakeBaseClass = <T>() : new() => Pick<T, keyof T> => (class {} as any);
export class ReconnectingWebSocketProvider extends fakeBaseClass<providers.WebSocketProvider>() {
private underlyingProvider: providers.WebSocketProvider;