Skip to content

Instantly share code, notes, and snippets.

@semperos
semperos / php_curl_example.php
Created October 20, 2010 20:21
Example using cURL library with PHP
<?php
$api_url = 'URL';
$token = 'TOKEN';
$curl_url = $api_url . '&token=' . $token;
// if you need to pull from a file, otherwise just generate the string
$content = file_get_contents('example.xml');
// cURL setup
$ch = curl_init($curl_url);
@semperos
semperos / drupal_batch_example.php
Created October 25, 2010 19:46
Example of Drupal Batch API
<?php
/**
* Import submit function
*/
function ret_user_import_upload_form_submit($form, &$form_state) {
if ($file = file_save_upload($source = 'ret_user_import_csv_file', $validators = array(), $dest = FALSE, $replace = FILE_EXISTS_REPLACE)) {
$offset = 0;
$headers = _ret_user_import_get_row($file->filepath, $offset);
if ($headers === FALSE) {
// there needs to be consistency, so enforce the existence of a 'header' row
@semperos
semperos / drupal_save_node.php
Created October 27, 2010 14:54
Create simple node programmatically
<?php
/**
* Programmatic creation of a node - as simple as it gets
*
* All Drupal nodes require a title; everything is else is optional or
* is auto-generated by Drupal upon saving the node to the database.
* This node has no extra CCK fields defined; we're simply giving it
* a title and a body. The author will be the super-admin user, and its
* published status will be "published".
@semperos
semperos / example_install.php
Created November 4, 2010 19:57
Example of *.install file for a custom module
<?php
/**
* @file Installation for ret reports
*/
function ret_report_api_install() {
drupal_install_schema('ret_report_api');
}
/**
@semperos
semperos / create_git_bundle.sh
Created December 1, 2010 19:59
Create a bundle and tag the codebase so we can make bundles incrementally
#!/bin/bash
# If on Windows, run this using the Git Bash
cd /path/to/git/repo
# Create a git bundle which includes only commits from
# the commit tagged "last_bundle" up to the present state
# of my "master" branch
git bundle create my_code.bundle last_bundle..master
@semperos
semperos / scrape-github-wiki.rb
Created December 27, 2010 20:42
JRuby script that logs you into Github and scrapes the "source" of your Wiki pages (i.e. what you typed) and saves it to a file.
require 'rubygems'
require 'celerity'
require 'hpricot'
require 'htmlentities'
# You obviously need all of the above gems installed before proceeding
user, password, project = ARGV # 'tobi', 'my_password', 'liquid'
raise(ArgumentError, "jruby scrape-github-wiki <username> <password> <projectname>") unless user and project and password
@semperos
semperos / map-to-html.clj
Created February 2, 2011 14:33
Function using hiccup to print a Clojure map as a "nested" HTML list.
(def example-map
{:a "foo" :b "bar" :other-stuff
{:item-1 ["hello" "clojure"],
:item-2 ["hello" "hiccup"],
:another-map
{:x "foo" :y "bar" :z "baz"}}
:c "wowza sauce"})
(defn map-to-html-list
"Clojure map to nested HTML list. Optional list-type and wrapper params taken as keywords hiccup understands, and optional sep parameter for the string to show key-value associations"
@semperos
semperos / hiccup-stracktrace.txt
Created February 7, 2011 21:03
Stacktrace caused by calling a hiccup.core function inside osc-scrape.util
Exception in thread "main" java.lang.RuntimeException: java.lang.RuntimeExceptio
n: java.lang.IllegalStateException: Var hiccup.core/render-attrs is unbound.
at clojure.lang.LazySeq.sval(LazySeq.java:47)
at clojure.lang.LazySeq.seq(LazySeq.java:56)
at clojure.lang.RT.seq(RT.java:450)
at clojure.core$seq.invoke(core.clj:122)
at clojure.core$apply.invoke(core.clj:540)
at osc_scrape.util$outline_to_html_list.invoke(util.clj:48)
at osc_scrape.util$gen_report.invoke(util.clj:82)
at osc_scrape.core$start_scrape.invoke(core.clj:137)
(ns foobar
(:gen-class
:name Foobar
:methods [[say-hello [] void]]))
(defn -say-hello []
(println "Saying hello from Clojure World!"))
Exception in thread "main" java.lang.IllegalArgumentException: Not a valid method name: say-hello (foobar.clj:1)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:5376)
@semperos
semperos / osc-scrape-gui.clj
Created February 28, 2011 21:40
GUI for a metadata scraping program
(ns osc-scrape.gui
(:use [osc-scrape core util])
(:import [javax.swing
JFrame JPanel JButton
JCheckBox JLabel
JOptionPane SwingWorker]
net.miginfocom.swing.MigLayout)
(:gen-class
:main true))