Skip to content

Instantly share code, notes, and snippets.

Avatar

Michael Baldry mikebaldry

View GitHub Profile
@mikebaldry
mikebaldry / ean_13.rb
Created Feb 21, 2018
Barby::Outputter to generate "proper" EAN-13 barcodes, with guard lines and code written below
View ean_13.rb
class EAN13Outputter < Barby::RmagickOutputter
attr_writer :font_size
def to_image(opts = {})
with_options opts do
canvas = Magick::Image.new(full_width, full_height)
bars = Magick::Draw.new
x1 = margin + offset_width
y1 = margin + (offset_height / 2)
View raw_socks5.rb
require "bundler"
Bundler.require
require "addressable"
require "socket"
require "ipaddr"
proxy_address = Addressable::URI.parse("socks5://user:password@host:1080")
remote_ip = IPAddr.new(IPSocket::getaddress("icanhazip.com"))
View test.ex
defmodule TestApp.Serializer do
defmacro __using__(_) do
quote do
defimpl Msgpax.Packer, for: __MODULE__ do
def transform(struct) do
type = String.replace_prefix(to_string(__MODULE__), "Elixir.Msgpax.Packer.TestApp.Data.", "")
Msgpax.Packer.Map.transform(Map.merge(Map.from_struct(struct), %{"__type" => type}))
end
end
end
View template.rb
class Template
def initialize(content)
@content = content
end
def render(context)
context = Hashie::Mash.new(context)
@content.gsub(/(%{([^}]+)})/) do
context[Regexp.last_match[2]]
View setup.sh
# delete index if exists
curl -XDELETE localhost:9200/test_nesting/
# create index with default settings
curl -XPOST localhost:9200/test_nesting/
# create mapping
curl -XPUT localhost:9200/test_nesting/link/_mapping -d '
{
"link" : {
View gist:7583901
"sort": {
"_script": {
"script": "long lowestPublishedAt; for (int i = 0; i < _source.sources.size(); i++) { Boolean foundInList = false; for (int x = 0; x < external_ids.size(); x++) { if (external_ids[x] == _source.sources[i].external_id) { foundInList = true; break; } } if (foundInList) { if (i == 0 || _source.sources[i].published_at < lowestPublishedAt) { lowestPublishedAt = _source.sources[i].published_at; } } } return lowestPublishedAt;",
"type": "number",
"params": {
"external_ids": [
"a99240f3",
"a217f93"
]
},
View gist:7354494
<script type="text/javascript">
window.notifications = <%= flash[:notifications].to_json %>;
</script>
growl.js.psuedo
--------
foreach (notification in window.notifications) {
showNotification(notification);
}
View blah.cs
class Bootstrapper : WindsorNancyBootstrapper {
private readonly IWindsorContainer _container;
public Bootstrapper(IWindsorContainer container)
{
_container = container;
}
protected override Castle.Windsor.IWindsorContainer GetApplicationContainer ()
{
View gist:7135962
Oct 24 11:37:02 ip-10-58-137-38 varnishd[1225]: Platform: Linux,3.4.62-53.42.amzn1.x86_64,x86_64,-sfile,-smalloc,-hcritbit
Oct 24 11:37:02 ip-10-58-137-38 varnishd[1225]: child (1226) Started
Oct 24 11:37:02 ip-10-58-137-38 varnishd[1225]: Child (1226) said Child starts
Oct 24 11:37:02 ip-10-58-137-38 varnishd[1225]: Child (1226) said SMF.s0 mmap'ed 1073741824 bytes of 1073741824
Oct 24 11:52:02 ip-10-58-137-38 varnishd[1225]: Manager got SIGINT
View test.rb
def extract_highlights(highlighted_string)
results = []
str = highlighted_string.dup
while start_index = str.index("<em>")
match_length = str[start_index..-1].index("</em>") - 4
results << [start_index, match_length]
You can’t perform that action at this time.