Skip to content

Instantly share code, notes, and snippets.

View ammaaim's full-sized avatar

Alex Balan ammaaim

View GitHub Profile
@ammaaim
ammaaim / shell-dir-exist
Created July 29, 2014 16:40
shell check if dir exist
# To check if a directory exists in a shell script you can use the following:
if [ -d "$DIRECTORY" ]; then
# Control will enter here if $DIRECTORY exists.
fi
#Or to check if a directory doesn't exist:
if [ ! -d "$DIRECTORY" ]; then
@ammaaim
ammaaim / 0_reuse_code.js
Created July 29, 2014 16:48
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@ammaaim
ammaaim / printer-reset.cmd
Created September 19, 2014 14:15
reset windows spool service with queue cleaning
del %windir%\system32\spool\printers\*
net stop spooler
net start spooler
@ammaaim
ammaaim / gist:99c5b5e51e6ff8ac97a8
Created November 2, 2014 09:22
rm github branch
git push origin --delete <branch-name>
@ammaaim
ammaaim / ruby-csv.rb
Last active August 29, 2015 14:09
ruby csv example
# in excel: file->import->CSV file
require 'csv'
# write csv
CSV.open("file.csv", "wb") do |csv|
csv << ["row", "of", "CSV", "data"]
csv << ["another", "row"]
# ...
end
@ammaaim
ammaaim / rails-import-from-csv.rb
Created November 12, 2014 13:36
ruby import model data from csv
require 'csv'
csv_text = File.read('filename.csv')
csv = CSV.parse(csv_text, :headers => true)
csv.each do |row|
Model.create!(row.to_hash)
end
@ammaaim
ammaaim / remove-all-older.sql
Created December 10, 2014 13:08
remove all older rows sql
-- FOR MySQL -disable safemode
SET SQL_SAFE_UPDATES = 0;
-- for example remove all older than '2014-10-01'
DELETE FROM `base-name`.`table-name` WHERE `table-name`.`date-field` < '2014-10-01';
@ammaaim
ammaaim / create-folder
Created July 20, 2015 08:36
Create folder if not exist
directory_name = "name"
Dir.mkdir(directory_name) unless File.exists?(directory_name)
@ammaaim
ammaaim / yaml.rb
Last active December 12, 2018 12:41
Read/Write YAML in Ruby
require 'yaml'
$db_file = 'filename.yaml'
def load_data
text = File.read 'db.yaml'
return YAML.load text
end
def store_data hash
@ammaaim
ammaaim / bsd_fopen.txt
Created September 3, 2015 07:03
Open Flags
The argument mode points to a string beginning with one of the following
sequences (Additional characters may follow these sequences.):
``r'' Open text file for reading. The stream is positioned at the
beginning of the file.
``r+'' Open for reading and writing. The stream is positioned at the
beginning of the file.
``w'' Truncate file to zero length or create text file for writing.