Skip to content

Instantly share code, notes, and snippets.

View mloberg's full-sized avatar
🐚
call me on my #!/bin/sh phone

Matt Loberg mloberg

🐚
call me on my #!/bin/sh phone
View GitHub Profile
@mloberg
mloberg / gist:5469030
Last active December 16, 2015 17:18
Append a gitignore template to your local .gitignore.
#!/usr/bin/env python
import os
import sys
import fcntl
import termios
import struct
import urllib2
import json
GITIGNORE_URL = "https://api.github.com/gitignore/templates"
<?php
function compareHashes($hashOne, $hashTwo)
{
$result = 0;
for ($i = 0; $i < strlen($hashOne); $i++) {
$charOne = substr($hashOne, $i, 1);
$charTwo = substr($hashTwo, $i, 1);
$intOne = base_convert($charOne, 16, 10);
@mloberg
mloberg / jquery.loader.js
Created June 29, 2011 20:05
Simple jQuery Plugin Loader
(function($){
$.load = function(options){
// check for something to load
if(options.src === undefined) return;
// load dependencies
if(options.deps !== undefined){
$.each(options.deps, function(key, value){
var type = value.split(".")[value.split(".").length - 1];
if(type === "js"){
$.getScript(value);
@mloberg
mloberg / mphp
Created October 3, 2016 19:45
Bash script for managing PHP versions on macOS (using Homebrew)
#!/usr/bin/env bash
#
# Copyright (c) 2016 Matthew Loberg
# Distributed under the MIT License (http://opensource.org/licenses/MIT)
#
# ==========================
# Manage PHP (uses Homebrew)
# ==========================
#
# Commands:
@mloberg
mloberg / npm.sh
Created April 21, 2017 23:00
WIP: Run npm via Docker
npm () {
[ -n "$NODE_VERSION" ] || NODE_VERSION="latest"
tty=
tty -s && tty=--tty
docker run \
$tty \
--interactive \
--rm \
--user $(id -u):$(id -g) \
@mloberg
mloberg / index.php
Created April 18, 2011 20:40
Last.fm Simple PHP Class
<?php
include_once('lastfm.php');
$lastfm = new LastFm('your-api-key');
$params = array(
'user' => 'mloberg'
);
print_r($lastfm->call('user.getInfo', $params));
@mloberg
mloberg / upload.rb
Created December 16, 2011 14:18
qq.FileUploader Ruby
directory = './tmp/'
# ajax upload
if params[:qqfile].class == String
name = params[:qqfile]
string_io = request.body
data_bytes = string_io.read
path = File.join(directory, name)
File.open(path, "w") do |f|
f.write(data_bytes)
end
@mloberg
mloberg / batch.py
Created March 2, 2018 20:09
Python Tools
from itertools import islice, chain
def batch(iterable, size):
iterator = iter(iterable)
for first in iterator:
yield chain([first], islice(iterator, size - 1))
@mloberg
mloberg / watermark.html
Created June 23, 2011 18:40
Watermark PHP
<img src="watermark.php?watermark=watermark.png&src=test.jpg" />
### Keybase proof
I hereby claim:
* I am mloberg on github.
* I am mloberg (https://keybase.io/mloberg) on keybase.
* I have a public key ASDcFyl0kafbvzkZ9nI-2-9d5Kk5XQMLUTnjNRw5p5s_DAo
To claim this, I am signing this object: