Skip to content

Instantly share code, notes, and snippets.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@imbolc
imbolc / certbot.py
Created February 26, 2018 06:16
Django command to dealing with certbot (let's encrypt, letsencrypt.org) and nginx
import os
from django.core.management.base import BaseCommand
from django.conf import settings
COMMAND = f'''
./var/env/bin/certbot {{}}
--config-dir=./var/certbot/cfg
--work-dir=./var/certbot/work
@imbolc
imbolc / target_blank.js
Created August 5, 2018 02:16
Set target="_blank" attribute for all the external links
!function () {
// target="_blank" for external links
var origin = location.host.replace(/www\./, '')
Array.prototype.slice.call(document.getElementsByTagName('a'))
.filter(function (a) { return a.host && !a.host.match(origin + '$') })
.forEach(function (a) { a.setAttribute('target', '_blank') })
}()
@imbolc
imbolc / filter_gateways.rb
Created August 11, 2018 00:20
Shopify script to filter country-specific payment methods
def allow_in(gateway, eligible_country_codes)
if Input.cart.shipping_address and eligible_country_codes.include?(Input.cart.shipping_address.country_code)
Output.payment_gateways = Input.payment_gateways
else
Output.payment_gateways = Input.payment_gateways.delete_if do |payment_gateway|
payment_gateway.name == gateway
end
end
end
@imbolc
imbolc / Debouncing.vue
Last active September 2, 2018 04:01
Vue debouncing #vuejs #vue.js #debounce #throttle #throttling
<template>
<div v-loading="loading">
<textarea v-model="text"></textarea>
{{ saving ? 'saving...' : '✓' }}
</div>
</template>
<script>
export default {
data: () => ({
text: '',
@imbolc
imbolc / rename_gateways.rb
Created September 16, 2018 13:23
Renaming of Shopify payment gateways
def rename_gateways(names)
Input.payment_gateways.each do |gateway|
# puts gateway.name
next unless names[gateway.name]
gateway.change_name(names[gateway.name])
end
Output.payment_gateways = Input.payment_gateways
end
rename_gateways({
@imbolc
imbolc / reorder_gateways.rb
Created September 16, 2018 13:39
Reorder Shopify payment gateways
def sort_gateways(order)
Output.payment_gateways = Input.payment_gateways.sort_by do |gateway|
# sometimes name isn't equal the title you see in payment page
# puts gateway.name
order.index(gateway.name) || 99
end
end
sort_gateways([
'Credit and Debit Cards',
@imbolc
imbolc / hide_by_country.rb
Created September 18, 2018 03:06
Restrict shopify payment method to be shown only in particular countries
def allow_in(gateway, allowed)
if Input.cart.shipping_address and allowed.include?(Input.cart.shipping_address.country_code)
Output.payment_gateways = Input.payment_gateways
else
Output.payment_gateways = Input.payment_gateways.delete_if do |payment_gateway|
payment_gateway.name == gateway
end
end
end
@imbolc
imbolc / django-axios.js
Last active December 21, 2018 16:22
Setup axios with django
axios.defaults.xsrfHeaderName = 'X-CSRFToken'
axios.defaults.xsrfCookieName = 'csrftoken'
@imbolc
imbolc / dot.py
Last active January 7, 2019 07:55
Dot product on rust vs numpy
import time
import numpy as np
tm = time.time()
size = 10000
cycles = 100
matrix = np.ones((size, size), dtype=int)
vector = np.array([-1 if x % 2 else 1 for x in range(size)])
for i in range(cycles):