Skip to content

Instantly share code, notes, and snippets.

View ysinc88's full-sized avatar

yair segal ysinc88

  • LED Yair
  • Israel
View GitHub Profile
@ysinc88
ysinc88 / number_range_hash.rb
Last active December 28, 2017 20:27
Hashes of numbers, used to populate collections
range_array = *(1..20)
@nums = range_array.map{|n| Hash[n, n] }.reduce({}, :merge)
#=> {1=>1, 2=>2, 3=>3, 4=>4, 5=>5, 6=>6, 7=>7, 8=>8, 9=>9, 10=>10, 11=>11, 12=>12, 13=>13, 14=>14, 15=>15, 16=>16, 17=>17, 18=>18, 19=>19, 20=>20}
@ysinc88
ysinc88 / error.log
Last active April 28, 2016 14:54
Rails+Nginx+Unicorn
[crit] 12429#0: *27 stat() "/home/user/soWed/public/" failed (13: Permission denied), client: 215.21.75.35, server: mamamia.xyz, request: "GET / HTTP/1.1", host: "mamamia.xyz"
@ysinc88
ysinc88 / caseWhereBetween.sql
Created April 24, 2016 12:57
SQL - combining case between and where
CREATE FUNCTION ys_payments (@ent int,@year int,@q int)
RETURNS TABLE
AS
RETURN
...
where year(reportingPeriod) = @year
and
case
when @q = 1 then month(reportingPeriod) between @q and @q + 2
when @q = 2 then month(reportingPeriod) between @q + 2 and @q + 4
@ysinc88
ysinc88 / console.rb
Created March 15, 2016 13:03
Mechanize login form - Simple via console
agent = Mechanize.new
agent.get("http://play.google.com/music/publish/")
form = agent.page.forms.first
/*
=> #<Mechanize::Form
{name nil}
{method "POST"}
{action "https://accounts.google.com/AccountLoginInfo"}
{fields
[hidden:0x605897a type: hidden name: Page value: PasswordSeparationSignIn]
@ysinc88
ysinc88 / duplicateUpcs.sql
Created December 18, 2015 12:30
tsql concat
select
r.name as release,a.name as artist,r.version,l.name as label,count(distinct r.upc) as upcCount,concat(distinct r.upc) as upcs
from releases r
join artists a on a.artistid = r.artistid
join labels l on l.labelid = r.labelid
where l.name = 'foo'
group by r.name, a.name,l.name,r.version,upcs
having count(distinct r.upc) > 1
order by upcCount desc
@ysinc88
ysinc88 / catalog_templates_controller.rb
Last active December 16, 2015 12:09
Loading xls with roo
class CatalogTemplatesController < ApplicationController
.
.
.
def parse
require 'roo'
require 'roo-xls'
workbook = Roo::Excel.new("/home/123.xls")
#!/bin/bash
datafile=$1
ctr=0;
while read line
do
# counter to keep track of line number
ctr=$((ctr + 1))
@ysinc88
ysinc88 / readme.txt
Last active November 11, 2015 18:13
Creating new lines from the commas inside quotes
So I have no code, because i have no idea how to do this...
I am looking for a link to start reading...
Taking this sample row:
original:
--bRP68Ey4M,Natalie Imbruglia Torn,16,0,USD,"Torn,,Torn,","GB1109700440,,GBARL0400487,",,",emipub|UMPG,,emipub|UMPG","Natalie Imbruglia,,Various,"
desired output:
=--bRP68Ey4M,Natalie Imbruglia Torn,16,0,USD,Torn,GB1109700440,,,Natalie Imbruglia
=--bRP68Ey4M,Natalie Imbruglia Torn,16,0,USD,,,,emipub|UMPG,
=--bRP68Ey4M,Natalie Imbruglia Torn,16,0,USD,Torn,GBARL0400487,,,Various
@ysinc88
ysinc88 / index.html
Last active September 19, 2015 19:46
Form log not working
<!DOCTYPE html >
<html lang="en"
ng-app="minmax" >
<head >
<title >Controllers</title >
<link href="../libs/bootstrap/bootstrap.min.css"
rel="stylesheet" >
<link href="main.css"
rel="stylesheet" >
</head >
@ysinc88
ysinc88 / seeds.rb
Created September 16, 2015 10:21
seeding from excel
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
require 'roo'
def fetch_excel_data