Skip to content

Instantly share code, notes, and snippets.

@ramses-lopez
ramses-lopez / calc-test.js
Created March 29, 2017 03:43
tape js test
var test = require('tape');
var calc = {
add: function(x,y){
return x+y*2
}
}
test('adding two numbers', function (t) {
var r = calc.add(2,2, 'this should add 2+2 & return 4')
@ramses-lopez
ramses-lopez / curl_paypal.php
Last active August 21, 2017 04:26
PHP cURL Post
<?php
// $paymentObject = '{
// 'intent': "sale",
// "payer": {
// "payment_method": "credit_card",
// "funding_instruments": [{
// "credit_card": {
// "number": "4032032647673208",
// "type": "visa",
@ramses-lopez
ramses-lopez / paypal_payment.js
Created August 21, 2017 02:21
Node -Paypal Payment
const c = require('chalk')
const fetch = require('node-fetch')
const inspect = require('util').inspect
const l = str => console.log(inspect( str, { depth: 'Infinite', colors: true }))
/*
Client ID
AXVggvfsNB7SfW_gZNZ7TenVbkW5pylY9s9W3U6edvw5JTRK7TvazrFSUnFc4bzW4xUgihfZCaPHhctH
@ramses-lopez
ramses-lopez / PostgreSQL cheatsheet
Last active October 3, 2019 13:46
Dump & restore cheatsheet
# Backup comfy tables & static_contents table
pg_dump -Fc --clean --if-exists --no-owner -t 'comfy_*' -t static_contents omx_staging > comfy_backup_20180723.sql
# Well..
dropdb omx_staging && createdb omx_staging
# Restore production data
pg_restore --no-owner -d omx_staging July232018-08_53_11.backup
# Restore comfy tables
// create instance
docker run -d -p 5432:5432 --name my-postgres -e POSTGRES_PASSWORD=mysecretpassword postgres
// enter instance
docker exec -it my-postgres bash
// ... create users, dbs, w/e ...
// Install psql on local machine
sudo apt-get install postgresql-client
@ramses-lopez
ramses-lopez / main.rb
Created November 20, 2018 17:22
GruesomeMagnificentWorkplace created by ramses_lopezs - https://repl.it/@ramses_lopezs/GruesomeMagnificentWorkplace
def block_example(&block)
puts 'This goes before the execution'
yield
puts 'This goes after the execution'
end
block_example do
puts 'awesome ruby code goes here!'
end
@ramses-lopez
ramses-lopez / vimrc
Last active September 30, 2020 15:37
.vimrc
" color column
set cc=100
set nu rnu
" Indentation w/o hard tabs
set expandtab
set shiftwidth=2
set softtabstop=2
set tabstop=2
set nowrap
set autoindent
@ramses-lopez
ramses-lopez / psqlrc
Last active December 24, 2018 03:33
psqlrc
\pset linestyle unicode
\pset border 2
\pset null '⌁'
\pset format wrapped
\timing
@ramses-lopez
ramses-lopez / delete_selected_sessions.sql
Last active April 22, 2019 17:07
Clear selected sessions from rails table
set bytea_output to 'escape';
-- delete
select session_id, decode(data, 'base64')::text
from sessions
where decode(data, 'base64')::text ilike '%return_to%'
and decode(data, 'base64')::text ilike '%password%new%';
@ramses-lopez
ramses-lopez / find_duplicates.sql
Created May 21, 2019 20:40
Example query for finding duplicates and using window functions
SELECT
opportunities.id "opp_id",
title,
expiry_date,
ROW_NUMBER() OVER dupes,
FIRST_VALUE(opportunities.id) OVER dupes "parent"
FROM opportunities
WINDOW dupes AS (PARTITION BY opportunities.title, opportunities.expiry_date ORDER BY opportunities.created_at)