Skip to content

Instantly share code, notes, and snippets.

View techsin's full-sized avatar
🏠
Working from home

techsin techsin

🏠
Working from home
  • New York, NY
View GitHub Profile
@techsin
techsin / img.js
Created March 21, 2024 10:46
encoding into image
// Function to encode secret data into image pixels
function encodeDataIntoImage(imageData, secretData) {
// Assuming imageData is a Uint8ClampedArray representing pixel data of the image
// and secretData is the string to be hidden
// Convert secretData into binary
let binarySecret = secretData.split('').map(char => char.charCodeAt(0).toString(2)).join('');
// Embed binary data into least significant bits of image pixel values
for (let i = 0; i < binarySecret.length; i++) {
@techsin
techsin / remove
Created May 27, 2015 02:49
remove
(function(){function k(a,b){var c=a.data;c.children.forEach(function(a){b.push(a.data.name)});(c=c.after)?e(c):(console.log(b),confirm("Delete All?")&&l(m()))}function m(){var a=0;f=setInterval(function(){n(a++);!d.length>a&&clearInterval(f)},200)}function n(a){$.ajax({url:"http://www.reddit.com/api/unsave",type:"post",data:{id:d[a]},headers:{"X-Modhash":g},success:function(){console.log("delete",a);0==a%10&&console.log("Eats a potato chip")}})}function e(a){var b=h;a&&(console.log("got after",a),
b=h+"&after="+a);setTimeout(function(){$.getJSON(b).done(function(a){k(a,d)})},200)}function l(a){$.getJSON("http://www.reddit.com/api/me.json").done(function(b){g=b.data.modhash;a()})}var d=[],g=null,h="http://www.reddit.com/user/"+window.location.href.match(/user\/([^/]*)/)[1]+"/saved.json?limit=100";(function(){if(!jQuery){var a=void 0,a=document.createElement("script");a.type="text/javascript";a.src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js";document.getElementsByTagName("head")[0].append
@techsin
techsin / solution.js
Created May 16, 2021 14:09
create-target-array-in-the-given-order
/**
* @param {number[]} nums
* @param {number[]} index
* @return {number[]}
* https://leetcode.com/problems/create-target-array-in-the-given-order/submissions/
*/
function Node(val) {
this.val = val;
this.next = null;
@techsin
techsin / width.js
Created April 30, 2021 13:54
Dimensions in JavaScript
console.log($0.offsetWidth)
console.log($0.clientWidth)
console.log($0.scrollWidth)
console.log($0.getBoundingClientRect().width)
console.log(getComputedStyle($0).width)
console.log($0.clientLeft)
console.log($0.offsetLeft)
console.log($0.scrollLeft)
console.log(innerWidth)
console.log(outerWidth)
@techsin
techsin / font.js
Created April 22, 2021 20:08
font props
{
'color': css.color,
'font-family': css.fontFamily,
'font-size': css.fontSize,
'font-style': css.fontStyle,
'font-variant': css.fontVariant,
'font-weight': css.fontWeight,
'letter-spacing': css.letterSpacing,
'line-height': css.lineHeight,
'text-align':css.textAlign ,
@techsin
techsin / scopeclosure.js
Last active February 27, 2021 17:57
scope closure
a = ['a','b', 'c']
for (let i = 0; i < 3; i++) {
var c = a[i];
setTimeout(()=> console.log(c)); // c c c
}
//is same as, var is function scoped
var c;
a = ['a','b', 'c']
for (let i = 0; i < 3; i++) {
@techsin
techsin / cookie.js
Created January 29, 2021 00:54
cookie parser
@techsin
techsin / sortEle.js
Created October 23, 2020 02:15
Sort Html Elements
// $container - css selector for nodes that need to be sorted
// $number - css selector for node with number
function sortElements($container, $number) {
const hash = new Map();
const list = Array.from(document.querySelectorAll($container));
for (let i = 0; i < list.length; i++) {
for (let j = i; j < list.length; j++) {
const element = list[i];
@techsin
techsin / worker.js
Last active October 18, 2020 23:16
Testing performance of service workers vs promises
function wrk() {
var blobURL = URL.createObjectURL(new Blob(['(',
function () {
for (let i = 0; i < 5000000000; i++) { } console.log(1000);
}.toString(),
')()'], { type: 'application/javascript' }));
const worker = new Worker(blobURL);
@techsin
techsin / cookie.js
Created September 10, 2020 15:51
Read and set cookie as a 3rd party