Skip to content

Instantly share code, notes, and snippets.

View fatuhoku's full-sized avatar

Hok Shun Poon fatuhoku

View GitHub Profile
@craigweston
craigweston / or_scopes.rb
Last active March 26, 2020 23:22 — forked from j-mcnally/or_scopes.rb
OR'ing scopes
module ActiveRecord
module Querying
delegate :or, :to => :all
end
end
module ActiveRecord
module QueryMethods
# OrChain objects act as placeholder for queries in which #or does not have any parameter.
# In this case, #or must be chained with any other relation method to return a new relation.
@lukejohnjones
lukejohnjones / parse_thumbnail
Created November 4, 2014 05:45
Parse.com thumbnail creation retaining aspect ratio
var Image = require("parse-image");
Parse.Cloud.beforeSave("_User", function(request, response) {
var user = request.object;
if (!user.get("profilePhoto")) {
response.error("Users must have a profile photo.");
return;
}
if (!user.dirty("profilePhoto")) {
@hopsoft
hopsoft / db.rake
Last active May 22, 2024 22:53
Rails rake tasks for dump & restore of PostgreSQL databases
# lib/tasks/db.rake
namespace :db do
desc "Dumps the database to db/APP_NAME.dump"
task :dump => :environment do
cmd = nil
with_config do |app, host, db, user|
cmd = "pg_dump --host #{host} --username #{user} --verbose --clean --no-owner --no-acl --format=c #{db} > #{Rails.root}/db/#{app}.dump"
end
puts cmd
@pulkitsinghal
pulkitsinghal / sample.js
Created May 3, 2014 00:27
Parse Cloud Code for checking if a user has the required role
Parse.Cloud.define('isAdmin', function(request, response){
if(!Parse.User.current()){
response.error('Request did not have an authenticated user attached with it');
}
else {
userHasRole(request.params.parseSessionToken, 'super') // ex: check if user has "super" role
.then(function(hasRole){
if(hasRole){
response.success({super: true});
}else{
@CodaFi
CodaFi / CFIMultiMap.c
Last active December 24, 2015 12:59
A fully bridged multimap implementation.
/*
* Copyright (c) 2013 CodaFi. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this