Skip to content

Instantly share code, notes, and snippets.

View rifttech's full-sized avatar
🐳
Focusing

Arthur Abramov rifttech

🐳
Focusing
View GitHub Profile
@rifttech
rifttech / username.java
Created April 8, 2015 20:06
get username/login
// in windows
String username = new com.sun.security.auth.module.NTSystem().getName();
// in Unix:
String username = new com.sun.security.auth.module.UnixSystem().getUsername();
// in Solaris:
String username = new com.sun.security.auth.module.SolarisSystem().getUsername();
@rifttech
rifttech / add-column.sql
Last active June 5, 2020 23:26
Drop someths sql server
if not exists(select * from sys.columns where Name = N'$COLUMN_NAME$' and Object_ID = Object_ID(N'$TABLE_NAME$'))
begin
alter table $TABLE_NAME$
ADD $COLUMN_NAME$ int DEFAULT(1)
end
go
@rifttech
rifttech / tmp_proc.sql
Created April 13, 2015 19:00
SQL Templates
/*@name=$name dependsOn={}*/
/*@start*/
if exists (select * from sysobjects o where o.id = OBJECT_ID(N'$name') and type in (N'PC',N'P'))
drop procedure $name
go
create procedure $name
as
begin
//code here..
end
@rifttech
rifttech / nodejs-read-file.js
Last active August 29, 2015 14:19
nodejs io read file by line
//Synchronous:
var fs = require('fs');
var array = fs.readFileSync('file.txt').toString().split("\n").forEach(function(line){
console.log(line);
});
//Asynchronous:
var fs = require('fs');
fs.readFile('file.txt', function(err, data) {
if(err) throw err;
@rifttech
rifttech / rm-dup-sql-srv2008.sql
Created April 22, 2015 10:13
removing duplicates from table(sql server 2008)
with cte as (
select row_number() over (
partition by
$column_names$
order by $orderby_column$ as rn
from $table_name$)
delete from cte
where rn > 1;
@rifttech
rifttech / truncate-time=in-getdate.sql
Last active August 29, 2015 14:19
SQL Server 2008 - Truncate time in 'Getdate'
select CONVERT(DATE,getdate(), 101) -- returns YYYY-MM-DD
/*OR...*/
select CAST(GETDATE() as Date) -- returns YYYY-MM-DD
public class MyWorker extends Thread {
private static int instance = 0;
private final Queue<String> queue;
public MyWorker(Queue queue) {
this.queue = queue;
setName("MyWorker:" + (instance++));
}
@Override
public class BlockingQueue implements Queue {
private java.util.Queue queue = new java.util.LinkedList();
/**
* Make a blocking Dequeue call so that we'll only return when the queue has
* something on it, otherwise we'll wait until something is put on it.
*
* @returns This will return null if the thread wait() call is interrupted.
*/
@rifttech
rifttech / copy-conf.xml
Created June 25, 2015 19:26
maven copy config
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<assembly>
<id>dist</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>true</includeBaseDirectory>
<dependencySets>
<dependencySet>