Skip to content

Instantly share code, notes, and snippets.

View gobijan's full-sized avatar
🏝️
Deep in the Caribbean...

Bijan Rahnema gobijan

🏝️
Deep in the Caribbean...
View GitHub Profile
@entries
for feed in Feed.all
@entries << feed.entries
end
i need to save distances between two sites => a Directions-Model should have something like
id
origin_id
destination_id
distance
How do I set this up via active record because origin and destination are both from the type site?
@gobijan
gobijan / gist:2106782
Created March 19, 2012 10:27
Referencing the same Model type under another name...
Post
has_many :upvotes <= Model: Vote
has_many :downvotes <= Model: Vote
Vote
Fields: user_id, comment
belongs_to :post <= as an upvote or downvote..
What I want to achieve:
@gobijan
gobijan / init.js
Last active December 30, 2015 16:39
chocolat autopep8 mixin
var execFile = require('child_process').execFile;
Hooks.addMenuItem("Actions/Python/autopep8", "cmd-alt-l", function() {
var type = Document.current().rootScope();
if ('python.source'.indexOf(type) !== -1) {
execFile("/usr/local/bin/autopep8", ["--aggressive", Document.current().path()], function(error, stdout, stderr) {
Recipe.run(function(recipe) {
recipe.text = stdout;
});
@gobijan
gobijan / gist:10749875
Created April 15, 2014 17:24
ng-really? An AngularJS directive that creates a confirmation dialog for an action. (props to asafge)
/**
* A generic confirmation for risky actions.
* Usage: Add attributes: ng-really-message="Are you sure?" ng-really-click="takeAction()" function
*/
angular.module('app').directive('ngReallyClick', [function() {
return {
restrict: 'A',
link: function(scope, element, attrs) {
element.bind('click', function(e) {
e.stopPropagation(); // In case you cancel and don't want events to be propagated.
@gobijan
gobijan / gist:1568fb2b35c517f36369
Created July 15, 2014 11:27
Golang HTTP Handler to Upload Image => Resize => Convert to JPEG => Save to Disk.
func UploadHandler(w http.ResponseWriter, r *http.Request) {
file, _, err := r.FormFile("file")
if err != nil {
log.Println(err)
http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
return
}
img, _, err := image.Decode(file)
@gobijan
gobijan / gist:d724de27e2aff8131676
Created November 13, 2014 00:02
Convert NSColor to Hex
func getHexFromColor(color: NSColor) -> NSString {
// Get the red, green, and blue components of the color
var r :CGFloat = 0
var g: CGFloat = 0
var b: CGFloat = 0
var a: CGFloat = 0
var rInt, gInt, bInt, aInt: Int
var rHex, gHex, bHex: NSString
// There seem to be problems with "climatically" and "fezzes" as passwords.
// When using "climatically": Program terminates with "openpgp: unsupported feature: public key version"
// When using "fezzes": Program terminates with "openpgp: invalid data: tag byte does not have MSB set"
// Expected behaviour would be a reinvokation of the prompt function in an endless loop until the right password is used.
package main
import (
"bytes"
"errors"
import Ember from 'ember';
export default Ember.Component.extend({
name: 'Bijan'
});
@gobijan
gobijan / controllers.application.js
Last active June 30, 2016 14:05
Guides Playground
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});