Skip to content

Instantly share code, notes, and snippets.

View mxlje's full-sized avatar
🌩️

Max Lielje mxlje

🌩️
View GitHub Profile
@mxlje
mxlje / settings.json
Created October 22, 2012 16:43
ST2 prefs
{
"caret_style": "smooth",
"color_scheme": "Packages/Color Scheme - Default/Monokai.tmTheme",
"file_exclude_patterns":
[
".DS_Store",
".gitkeep",
"*.css"
],
@mxlje
mxlje / Preferences.json
Created November 29, 2012 17:10
ST2Settings
{
"caret_style": "smooth",
"color_scheme": "Packages/Color Scheme - Default/Monokai.tmTheme",
"file_exclude_patterns":
[
".DS_Store",
".gitkeep"
],
"folder_exclude_patterns":
[
@mxlje
mxlje / get.php
Created February 11, 2013 10:48
Display current location on website, based on public Dropbox file
<?php
# File to load
$file = curl_init('http://dl.dropbox.com/u/YOUR-ID/location.txt');
curl_setopt($file,CURLOPT_USERAGENT,'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:7.0.1) Gecko/20100101 Firefox/7.0.1');
$html = curl_exec($file);
return $html;
?>
@mxlje
mxlje / md5.php
Created March 1, 2013 15:01
md5 generator
<?php
$i=0;
while ($i<= 40) {
echo md5(rand(0,20000)) . "<br>";
$i++;
}
?>
<url>
<loc>http://yourdomain.com{{post.url}}/</loc>
<changefreq>weekly</changefreq>
<priority>0.80</priority>
</url>
@mxlje
mxlje / sinatra-datamapper.rb
Created May 29, 2013 22:12
playing around with Sinatra & DataMapper
require 'sinatra'
require 'data_mapper'
require 'json'
# Authentication
# use Rack::Auth::Basic, "Restricted Area" do |username, password|
# username == 'admin' and password == 'admin'
# end
# set json as content type for all requests
@mxlje
mxlje / string.rb
Created July 12, 2013 10:02
Ruby method for cleaning URL strings for display
class String
# remove protocol, www, and trailing slash from URL string
def to_clean_url
u = self
if u.start_with?('http://www.')
u = u[11..-1]
elsif u.start_with?('https://www.')
u = u[12..-1]
@mxlje
mxlje / one_line_server
Last active December 20, 2015 06:39
One liner ruby webserver
# run this in the terminal
# via http://ruby5.envylabs.com/episodes/419-episode-383-july-2-2013
ruby -run -e httpd . -p 5000
# Checks status code of multiple URLs and prints them
require "mechanize"
urls = [
'http://maxlielje.co'
]
@agent = Mechanize.new
@mxlje
mxlje / footnotes.rb
Last active December 31, 2015 02:28
footnotes
class Redcarpet::Render::HTML
def footnote_ref(number)
@article_id ||= [*('a'..'z'),*('0'..'9')].shuffle[0,4].join
fn_ref = "<sup id='fnref-#{@article_id}-#{number}'>"
fn_ref << "<a href='#fn-#{@article_id}-#{number}' rel='footnote'>"
fn_ref << "#{number}</a></sup>"
end
def footnote_def(content, number)