Skip to content

Instantly share code, notes, and snippets.

View israeljrs's full-sized avatar

Israel Junior israeljrs

View GitHub Profile
@israeljrs
israeljrs / 20101004063749_create_photos.rb
Created August 6, 2019 17:18 — forked from macek/20101004063749_create_photos.rb
How to save uploaded files to your database in Rails
# db/migrate/20101004063749_create_photos.rb
class CreatePhotos < ActiveRecord::Migration
def self.up
create_table :photos do |t|
t.string :name, :null => false
t.binary :data, :null => false
t.string :filename
t.string :mime_type
t.timestamps
@israeljrs
israeljrs / rails-jsonb-queries
Created July 3, 2019 12:19 — forked from mankind/rails-jsonb-queries
Rails-5 postgresql-9.6 jsonb queries
http://stackoverflow.com/questions/22667401/postgres-json-data-type-rails-query
http://stackoverflow.com/questions/40702813/query-on-postgres-json-array-field-in-rails
#payload: [{"kind"=>"person"}]
Segment.where("payload @> ?", [{kind: "person"}].to_json)
#data: {"interest"=>["music", "movies", "programming"]}
Segment.where("data @> ?", {"interest": ["music", "movies", "programming"]}.to_json)
Segment.where("data #>> '{interest, 1}' = 'movies' ")
Segment.where("jsonb_array_length(data->'interest') > 1")
@israeljrs
israeljrs / linked_list.c
Last active February 21, 2019 01:31
Exemplo de lista encadeada para meu artigo no medium.
#include <stdio.h>
#include <stdlib.h>
//Estrutura base do nó.
struct node
{
int nData;
struct node *pLink;
};
@israeljrs
israeljrs / home-page.component.ts
Created February 18, 2019 16:27
home page ts para o exemplo rxjs timeout
import { Component, OnInit } from '@angular/core';
import { WebRequestService } from '../services/web-request.service';
@Component({
selector: 'app-home-page',
templateUrl: './home-page.component.html',
styleUrls: ['./home-page.component.scss']
})
export class HomePageComponent implements OnInit {
@israeljrs
israeljrs / web-request.service.ts
Created February 18, 2019 16:25
exemplo de service.
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { timeout } from 'rxjs/operators';
@Injectable({
providedIn: 'root'
})
export class WebRequestService {
@israeljrs
israeljrs / home-page.component.html
Created February 18, 2019 16:21
home page de exemplo para o arquivo no medium
<div class="container">
<div class="row mt-2">
<div class="col">
<div class="jumbotron">
<h3 class="text-center">{{msg}}</h3>
</div>
</div>
</div>
<div class="row">
<div class="col text-center">
@israeljrs
israeljrs / app-routing.module.ts
Created February 18, 2019 16:16
Modulo de exemplo para home do projeto
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { HomePageComponent } from './home-page/home-page.component';
const routes: Routes = [
{ path: '', component: HomePageComponent },
{ path: '**', redirectTo: '' }
];
@NgModule({
@israeljrs
israeljrs / cv2ff.cpp
Created January 4, 2019 16:45 — forked from yohhoy/cv2ff.cpp
Convert from OpenCV image and write movie with FFmpeg
/*
* Convert from OpenCV image and write movie with FFmpeg
*
* Copyright (c) 2016 yohhoy
*/
#include <iostream>
#include <vector>
// FFmpeg
extern "C" {
#include <libavformat/avformat.h>
@israeljrs
israeljrs / docker.md
Created December 21, 2018 23:42
Docker commands
  1. Show all images docker images

  2. Show all running containers docker ps

  3. Show all running and stopped containers docker ps -a

  4. Run an container

@israeljrs
israeljrs / uuid.rb
Created November 4, 2018 21:27
File to add support to uuid in rails apps add this file in config/initializer/uuid.rb
Rails.application.config.generators do |g|
g.orm :active_record, primary_key_type: :uuid
end