Skip to content

Instantly share code, notes, and snippets.

public class Program
{
static private Queue<long> lifo = new Queue<long>();
static void walk(object[] root)
{
if (root == null) throw new ArgumentNullException(nameof(root));
foreach (var o in root)
{
@ip75
ip75 / PasswordPolicyByBy.cs
Last active November 1, 2022 17:20
domain Password Policy By By. C# code to set random password several times that domain password policy require and then set your lovely password.
void Main()
{
string sDomain = "ad.microsoft.com";
string sServiceUser = "username";
string sServicePassword = "account_old_password";
string sNewServicePassword = "account_new_password";
var pc = new PrincipalContext(ContextType.Domain, sDomain, sServiceUser, sServicePassword);
@ip75
ip75 / treeview.sql
Created April 16, 2019 14:32
get view of tree using select. oracle 11g
------------------- HIERARCHYID => MERCID ---------------------------
select lpad(' ', 6 * level) || h.displayname as Tree,
hd.value mercid,
h.hierarchyid,
h.authid,
h.searchkey,
ad.dataid
from AUTHHIERARCHY h
left join hierarchydata hd
on hd.hierarchyid = h.hierarchyid
@ip75
ip75 / postgre-recursive.sql
Last active November 1, 2022 17:18
example of recursive select in postgres
--- in database of ФИАС get address records recursively until root record
WITH RECURSIVE parent AS
( SELECT a.*
FROM addrobj a
WHERE a.aoguid = @locality
AND a.actstatus = 1
UNION ALL
SELECT ao.*
FROM parent p
@ip75
ip75 / TreeFromList.cs
Last active November 1, 2022 17:17
C# code to generate tree objects from list of addresses. Item in list looks like "root.child1.child2.child3"
public abstract class BranchNode
{
public int Id { get; set; }
public string Name { get; set; }
public string Path { get; set; }
[NotMapped]
public string ParentPath
{
get
{
@ip75
ip75 / 0ring.asm
Last active November 1, 2022 17:09
try to execute code in 0 ring by setting flag in MSR_LSTAR register. AMD64
format PE64 GUI 5.0
include 'WIN64WX.INC'
section '.data' data readable writeable
_start TCHAR 'lets start the game...',0
_ring0 TCHAR 'We are in ring 0',0
_system_lstar dq 0
section '.code' code readable executable
@ip75
ip75 / 108.system-backup
Created November 1, 2022 17:05
periodic script to make backup of system on flash drive FreeBSD 13. Scan HDD in system and send SMART to root
#!/bin/sh -
#
# $FreeBSD$
#
if [ -r /etc/defaults/periodic.conf ]; then
. /etc/defaults/periodic.conf
source_periodic_confs
fi
#!/bin/sh
zone_base_path='/usr/local/etc/nsd/'
update_serial() {
acme_fqdn=$1
zone_full_path=$2
# get serial number
SELECT (regexp_match(m.file_url, '^.+/(.+)$'))[1] FROM media m WHERE m.file_url LIKE 'http%';
UPDATE media
SET file_url = (regexp_match(file_url, '^.+/(.+)$'))[1]
WHERE file_url LIKE 'http%';
@ip75
ip75 / bulk_import_with_chunks.go
Last active April 27, 2023 17:22
import huge CSV file to postgresql. Using sized channel to make a queue with chunks. Reader pushes chunks to queue in one thread and the dumper writes records in other thread
package psql
import (
"database/sql"
"encoding/csv"
"fmt"
"io"
"os"
"regexp"
"sync"