Skip to content

Instantly share code, notes, and snippets.

View mikebaldry's full-sized avatar

Michael Baldry mikebaldry

View GitHub Profile
@mikebaldry
mikebaldry / ean_13.rb
Created February 21, 2018 10:13
Barby::Outputter to generate "proper" EAN-13 barcodes, with guard lines and code written below
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)
> ./ruby test.rb
test.rb:9: warning: 'sub!' called on a string that could, in the future be frozen. string created at test.rb:4
test.rb:14: warning: '[]=' called on a string that could, in the future be frozen. string created at test.rb:4
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"))
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
# 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" : {
"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"
]
},
<script type="text/javascript">
window.notifications = <%= flash[:notifications].to_json %>;
</script>
growl.js.psuedo
--------
foreach (notification in window.notifications) {
showNotification(notification);
}
class Bootstrapper : WindsorNancyBootstrapper {
private readonly IWindsorContainer _container;
public Bootstrapper(IWindsorContainer container)
{
_container = container;
}
protected override Castle.Windsor.IWindsorContainer GetApplicationContainer ()
{
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
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]