Skip to content

Instantly share code, notes, and snippets.

Avatar

Sijawusz Pur Rahnama Sija

View GitHub Profile
View string_enum.cr
macro string_enum(name, &block)
enum {{name}}
{% for exp in block.body.expressions %}
{% if exp.is_a?(Assign) %}
{{exp.target}}
{% else %}
{{exp}}
{% end %}
{% end %}
View synchronized.cr
struct Synchronized(T)
protected getter __wrapped__ : T
def initialize(wrapped : T = T.new, protection : Mutex::Protection = :reentrant) forall T
@__wrapped__ = wrapped
@__lock__ = Mutex.new(protection)
end
macro method_missing(call)
@__lock__.synchronize do
@Sija
Sija / run-with-retry-on-pattern.yaml
Created Apr 11, 2020
CircleCI Orb allowing to retry jobs failing with certain pattern
View run-with-retry-on-pattern.yaml
# This code is licensed from CircleCI to the user under the MIT license. See
# https://circleci.com/orbs/registry/licensing for details.
version: 2.1
description: Run commands with retry
commands:
run-with-retry:
description: Run command with retry
parameters:
@Sija
Sija / angular-typeform.coffee
Last active Oct 8, 2018
Typeform embed module for AngularJS 1.x
View angular-typeform.coffee
'use strict'
###*
# @ngdoc overview
# @name angularTypeform
# @description
# This module contains a directive that allows you easily embed a typeform
# in your angular 1.x app taking care about state changes
###
angular.module 'angularTypeform', []
View .screenrc
startup_message off
#defbce on
#deflog on
ignorecase on
vbell on
autodetach on
altscreen on # fix for residual editor text
defutf8 on
hardcopy_append on
compacthist on
@Sija
Sija / build_nginx.sh
Last active Mar 30, 2017 — forked from MatthewVance/build_nginx.sh
Fetch, build, and install the latest nginx with the latest OpenSSL for RaspberryPi
View build_nginx.sh
#!/usr/bin/env bash
# make script exit if a simple command fails and
# make script print commands being executed
set -e -x
# names of latest versions of each package
export VERSION_PCRE=pcre-8.39
export VERSION_OPENSSL=openssl-1.0.2f
export VERSION_NGINX=nginx-1.9.11
View macro_magic.cr
module MacroMagic
def initialize(**attributes)
{% for var in @type.instance_vars %}
if arg = attributes[:{{var.name.id}}]?
@{{var.name.id}} = arg
end
{% end %}
end
private def instance_var_get(name)
View retry.cr
def retry(limit, *, backoff = nil)
attempts = 1
loop do
return yield
rescue error
raise error if attempts == limit
sleep(backoff * attempts) if backoff
attempts += 1
end
end
@Sija
Sija / .htaccess
Created Jul 26, 2016
no-www mod_rewrite apache .htaccess redirect
View .htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
# Preserve HTTP/HTTPS protocol in .htaccess redirects
# http://stackoverflow.com/a/20419821/601064
RewriteCond %{HTTPS} =on
RewriteRule ^(.*)$ - [env=proto:https]
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ - [env=proto:http]
View assert.cr
class AssertionError < Exception
end
# If `cond` is `false`, raise `exc`.
# If `exc` is not provided, `AssertionError` will be raised instead with information about the faulty expression.
# If the expression is a comparison, the result of each side of the comparison will also be shown.
macro assert(cond, exc = nil)
unless {{ cond }}
{% if exc %}
raise {{ exc }}