Skip to content

Instantly share code, notes, and snippets.

View ngm's full-sized avatar
🙂

Neil M ngm

🙂
View GitHub Profile
@ngm
ngm / tree_hash.rb
Created November 27, 2011 12:42
Seven Languages in Seven Weeks - Ruby - Day 2 - Tree
class Tree
attr_accessor :children, :node_name, :depth
def initialize(structure, depth)
@node_name = structure.keys.first
@depth = depth
@children = structure.values.first.map { |name,child| Tree.new({name,child}, depth+1) }
end
@ngm
ngm / grep.rb
Created November 27, 2011 15:01
Seven Languages in Seven Weeks - Ruby - Day 2 - Grep
puts
print "File name: "
filename = gets.chomp
puts
print "Search term: "
phrase = gets.chomp
File.open(filename, "r") do |file|
@ngm
ngm / guess_the_number.rb
Created November 27, 2011 15:06
Seven Languages in Seven Weeks - Ruby - Day 1 - Guess the number
puts "\nHello. What's your name?"
print "[Your name]: "
name = gets.chomp
puts
puts "Hello #{name}."
theMagicNumber = rand(100)+1
@ngm
ngm / acts_as_csv_module.rb
Created November 29, 2011 23:09
Seven Languages in Seven Weeks - Ruby - Day 3 - CsvRow
module ActsAsCsv
include Enumerable
def self.included(base)
base.extend ClassMethods
end
module ClassMethods
def acts_as_csv
@ngm
ngm / fibonacci_loopy.io
Created December 3, 2011 16:05
Seven Languages in Seven Weeks - Io - Day 2 - Fibonacci
fibonacci_loopy := method(n,
fib_list := List clone
for(i, 0, n-1,
if (i == 0 or i == 1,
fib_list append(1),
fib_list append(fib_list at(i-2) + fib_list at(i-1))
)
)
fib_list at(fib_list size-1)
@ngm
ngm / devbox.boxstarter
Last active April 1, 2016 14:42
Boxstarter Script
# antivirus
cinst autohotkey # avg installer uses autohotkey...
cinst avgantivirusfree
# windows updates + reboot
Install-WindowsUpdate -acceptEula
if (Test-PendingReboot) { Invoke-Reboot }
# iis
cinst IIS-WebServerRole -source windowsfeatures
@ngm
ngm / packages.el
Last active November 13, 2019 21:44
Basic spacemacs org-brain layer
;; put this file in ~/.emacs.d/private/org-brain
;; then add org-brain into your dotspacemacs-configuration-layers in .spacemacs
(defconst org-brain-packages
'(org-brain)
)
;; see https://github.com/Kungsgeten/org-brain#setup-and-requirements
(defun org-brain/init-org-brain ()
(use-package org-brain
@ngm
ngm / messy.html
Created July 21, 2017 09:00
HTML to be cleaned
<p style="margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Helvetica; color: rgb(6, 2, 1); -webkit-text-stroke-width: initial; -webkit-text-stroke-color: rgb(6, 2, 1);"><span style="font-kerning: none"><b>Aylesbury Restart Party &amp; Makers' Fair</b></span></p>
<p style="margin-bottom: 0px; line-height: normal; font-family: 'Lucida Grande'; color: rgb(6, 2, 1); -webkit-text-stroke-width: initial; -webkit-text-stroke-color: rgb(6, 2, 1);"><span style="font-kerning: none"><b>Jul 22, 2017</b></span></p>
<p style="margin-bottom: 0px; line-height: normal; font-family: 'Lucida Grande'; color: rgb(6, 2, 1); -webkit-text-stroke-width: initial; -webkit-text-stroke-color: rgb(6, 2, 1); background-color: rgb(157, 215, 226); min-height: 17px;"><span style="font-kerning: none"><b></b></span><br></p>
<p style="margin-bottom: 0px; line-height: normal; font-family: 'Lucida Grande'; color: rgb(6, 2, 1); -webkit-text-stroke-width: initial; -webkit-text-stroke-color: rgb(6, 2, 1);"><span style="font-kerni
function add_mastodon_syndication_target($synd_urls, $user_id)
{
$masto_target['uid'] = "social_coop";
$masto_target['name'] = "social.coop";
$synd_urls[] = $masto_target;
return $synd_urls;
}
add_filter("micropub_syndicate-to", "add_mastodon_syndication_target", 10, 2);
@ngm
ngm / functions.php
Created March 28, 2019 22:50
Wordpress embed handler for invidio.us
wp_embed_register_handler( 'invidious_watch', '#https?://invidio\.us/watch\?v=([A-Za-z0-9\-_]+)#i', 'wp_embed_handler_invidious' );
wp_embed_register_handler( 'invidious_embed', '#https?://invidio\.us/embed/([A-Za-z0-9\-_]+)#i', 'wp_embed_handler_invidious' );
function wp_embed_handler_invidious( $matches, $attr, $url, $rawattr ) {
$embed = sprintf(
'<iframe src="https://invidio.us/embed/%1$s" frameborder="0" scrolling="no" marginwidth="0" marginheight="0" width="600" height="400"></iframe>',
esc_attr($matches[1])
);
return $embed;
}