Skip to content

Instantly share code, notes, and snippets.

@gregfroese
gregfroese / gist:4124753
Created November 21, 2012 13:04
Posting an image in RubyMotion using BubbleWrap and saving it in Rails
## RubyMotion
imageData = UIImage.UIImageJPEGRepresentation(@image_view.image, 1)
encodedData = [imageData].pack("m0")
data["image"] = encodedData
BW::HTTP.post("http://localhost:3000/upload}", {payload: data}) do |response|
if response.ok?
end
end
public function editAboutMe_ajax($params) {
$this->show_layout = false;
$resp = new SilkAjax();
$this->set("params", $params);
$this->set("formType", "edit");
$resp->replace_html("#AboutMe", $this->render_partial("edit_about_me_ajax.tpl"));
return $resp->get_result();
}
$friendsActivity = orm("UserActivity")->find_all(array("join" => array("INNER JOIN silk_friends on friends.user_id = silk_user_activity.user_id"), "conditions" => array("friends.user_id = ?", $params["user_id"])));
object(__PHP_Incomplete_Class)#3 (16) {
["__PHP_Incomplete_Class_Name"]=>
string(6) "mpUser"
["params"]=>
array(11) {
["id"]=>
string(2) "26"
["username"]=>
string(9) "braindead"
["password"]=>
<?php
class mpUser extends SilkUser {
public function __construct(){
parent::__construct();
}
public function setup() {
$this->create_has_many_association("friends", "Friend", "user_id");
$this->create_has_many_association("activity", "UserActivity", "user_id");
// $this->create_belongs_to_association("activity", "user_activity", "user_id");
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>{$title}</title>
{javascript file="lib/silk/jquery/jquery.js"}
{javascript file="lib/silk/jquery/jquery.color.js"}
{javascript file="lib/silk/jquery/jquery.silk.js"}
{stylesheet}
/**
* Fills an object with posted form variables
*
* @param array Contains hash of values to load into the object (used in conjunction with SilkForm::auto_form)
*/
function fill_object_form($params) {
foreach($params as $key=>$value) {
$this->$key = $value;
}
}
public function editAboutMe_ajax($params) {
$form = SilkForm::create_form_start(array("remote" => "true", "url" => "/silk/mp/portfolio/saveAboutMe_ajax"));
$form .= SilkForm::create_input_textarea(array("value" => $params["description"], "cols" => "60", "name" => "description"));
$form .= SilkForm::create_input_hidden(array("name" => "id", "value" => $params["id"]));
$form .= "<br />";
$form .= silkform::create_input_submit(array("value" => "Save"));
$form .= SilkForm::create_form_end();
$this->show_layout = false;
greg@ubuntu:/var/www/silk/lib$ git status
# On branch master
# Changed but not updated:
# (use "git add/rm <file>..." to update what will be committed)
#
# deleted: ../config/routes.php.orig
# deleted: ../config/setup.yml.orig
# modified: ../index.php
# modified: silk/classes/class.silk_ajax.php
# modified: silk/classes/class.silk_application.php
@gregfroese
gregfroese / routes.js
Created August 12, 2014 14:23
Protecting routes with authentication in Express
var express = require('express');
var router = express.Router();
var bodyParser = require('body-parser');
var jwtauth = require('../../../jwtauth.js');
router.get('/', [bodyParser(), jwtauth], function(req, res) {
//jwtauth is run automatically and will populate req.user if there is a valid token supplied
if(!req.user) {
res.status(401).send({error: "Unauthorized access"});
return