Skip to content

Instantly share code, notes, and snippets.

@walidvb
walidvb / count_database_rows.rb
Created September 2, 2021 14:01
Count all rows from all tables on rails
class DatabaseReport
def entry_counts
tables = table_model_names.map do |model_name|
entity = model_name.constantize rescue nil
next if entity.nil?
[entity.to_s, entity.count]
end.compact
total = tables.reduce(0) do |acc, curr|
puts "#{curr[0]}: #{curr[1]}"
acc + curr[1]
@walidvb
walidvb / _requestPermissions_example.js
Last active November 13, 2019 21:25
This allows displaying a dialog to the user before actually requesting permissions from the OS. Ultimately, it allows to request that permission multiple times, which iOS prevents
import requestPermissions from './requestPermissions'
requestPermission(pickFromCamera, {
permissionNames: ['CAMERA', 'CAMERA_ROLL'],
alertTitle: '📷Camera📸',
alertBody: 'Use your camera now.',
})
// Only request every n times this is run
@walidvb
walidvb / Gemfile
Created May 20, 2016 16:23
RailsAdmin config for translatable models
#### I18n
gem 'rails-i18n', '~> 4.0.0'
gem 'globalize'
gem 'rails_admin', github: 'sferik/rails_admin'
gem 'rails_admin_globalize_field'
myApp.factory('dataThing',function($q,$http){
var thatData = null;
return {
getData : function(){
//create a promise
var deferredData = $q.defer()
anonymous
anonymous / gist:8656313
Created January 27, 2014 20:12
squarez
int samplesPerFrame = 32;
int numFrames = 48;
float shutterAngle = .8;
int[][] result;
float time;
void draw() {
for (int i=0; i<width*height; i++)
for (int a=0; a<3; a++)
result[i][a] = 0;
innitApp.provider('API',function(){
//temp storage for new collection
var _collections = []
//holds model references
var _models = {}
return {
//this fires when the provider is injected
$get : ['$resource',function($resource){
@ascot21
ascot21 / active_admin.js
Created January 6, 2014 03:44
Inline Editing in ActiveAdmin with Best In Place Gem
//= require jquery
//= require best_in_place
//= require jquery.purr
//= require active_admin/base
$(document).ready(function() {
$(".best_in_place").best_in_place()
$('.best_in_place').bind("ajax:success", function () {$(this).closest('tr').effect('highlight'); });
$(document).on('best_in_place:error', function(event, request, error) {
@piscisaureus
piscisaureus / pr.md
Created August 13, 2012 16:12
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@jgarber
jgarber / MIT-LICENSE.txt
Created April 4, 2012 14:57
Responsive video
Copyright (c) 2011 ZURB, http://www.zurb.com/
<!doctype html>
<!-- http://taylor.fausak.me/2015/01/27/ios-8-web-apps/ -->
<html>
<head>
<title>iOS 8 web app</title>
<!-- CONFIGURATION -->